question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Searching in JAMS with `None` and `str` values

See original GitHub issue

I’m getting a TypeError when searching annotations within a JAMS file that contain a specific key that can either be a string or a None.

Here an example:

when I do something this: jam.search(namespace="segment_open").search(**{"Sandbox.boundaries_id": "sf"})

and some annotations inside jam have boundaries_id=None and others have boundaries_id="sf", the search method raises a TypeError, like this:

/home/uri/anaconda3/lib/python3.6/site-packages/jams/core.py in search(self, **kwargs)
   1340 
   1341         for annotation in self:
-> 1342             if annotation.search(**kwargs):
   1343                 results.append(annotation)
   1344 

/home/uri/anaconda3/lib/python3.6/site-packages/jams/core.py in search(self, **kwargs)
    449 
    450                 if isinstance(obj, JObject):
--> 451                     match |= obj.search(**r_query)
    452 
    453         return match

/home/uri/anaconda3/lib/python3.6/site-packages/jams/core.py in search(self, **kwargs)
    442         for key in r_query:
    443             if hasattr(self, key):
--> 444                 match |= match_query(getattr(self, key), r_query[key])
    445 
    446         if not match:

/home/uri/anaconda3/lib/python3.6/site-packages/jams/core.py in match_query(string, query)
   1836 
   1837     elif isinstance(query, six.string_types):
-> 1838         return re.match(query, string) is not None
   1839 
   1840     else:

/home/uri/anaconda3/lib/python3.6/re.py in match(pattern, string, flags)
    170     """Try to apply the pattern at the start of the string, returning
    171     a match object, or None if no match was found."""
--> 172     return _compile(pattern, flags).match(string)
    173 
    174 def fullmatch(pattern, string, flags=0):

TypeError: expected string or bytes-like object

Is there a way to circumvent this? Shouldn’t search allow for this type of searches? Thanks!

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
urinietocommented, Mar 20, 2017

I think you missed a is not None in your work around. This seems to work now:

J.search(**{'Sandbox.foo': lambda x: isinstance(x, six.string_types) and re.match('bar', x) is not None})
0reactions
bmcfeecommented, Mar 20, 2017

I think you missed a is not None in your work around.

Yeah, sorry about that – you’re right.

Read more comments on GitHub >

github_iconTop Results From Across the Web

JAMS 7.X User Guide
ValidationType This property allows you to select the type of validation JAMS can perform on the Parameter value. The validation types are: None:...
Read more >
jams 0.3.2 documentation
Search a JAMS object for matching objects. Parameters: kwargs : keyword arguments.
Read more >
Pythonic way of converting 'None' string to None
Let's say I have the following yaml file and the value in the 4th row should be None . How can I convert...
Read more >
TypeError: can only concatenate str (not "NoneType") to str
The Python "TypeError: can only concatenate str (not "NoneType") to str" occurs when we try to concatenate a string and a None value....
Read more >
How do I define search filters? - JAM Software
Defining a filter. In order to create a new filter, follow these steps: 1.Click "+". 2.In the first selection box, select what you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found