Skip to content

Commit

Permalink
Allows empty dicts in groups (#53)
Browse files Browse the repository at this point in the history
* Allows empty dicts in groups
  • Loading branch information
tomdele committed Apr 14, 2020
1 parent 6b2a847 commit a5f2136
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions bluepysnap/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,9 @@ def _properties_mask(self, queries):

def _operator_mask(self, queries):
"""Handle the query operators '$or', '$and'."""
if len(queries) == 0:
return np.full(len(self._data), True)

# will pop the population and or/and operators so need to copy
queries = deepcopy(queries)
first_key = list(queries)[0]
Expand Down Expand Up @@ -328,6 +331,7 @@ def ids(self, group=None, limit=None, sample=None):
The available group parameter values:
>>> nodes.ids(group=None) # returns all IDs
>>> nodes.ids(group={}) # returns all IDs
>>> nodes.ids(group=1) # returns the single ID if present in population
>>> nodes.ids(group=[1,2,3]) # returns list of IDs if all present in population
>>> nodes.ids(group="node_set_name") # returns list of IDs matching node set
Expand Down
7 changes: 6 additions & 1 deletion tests/test_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ def test__node_population_mask(self):
def test_ids(self):
_call = self.test_obj.ids
npt.assert_equal(_call(), [0, 1, 2])
npt.assert_equal(_call(group={}), [0, 1, 2])
npt.assert_equal(_call(group=[]), [])
npt.assert_equal(_call(limit=1), [0])
npt.assert_equal(len(_call(sample=2)), 2)
npt.assert_equal(_call(0), [0])
Expand All @@ -161,12 +163,15 @@ def test_ids(self):
# same query with a $and operator
npt.assert_equal(_call({"$and": [{Cell.MTYPE: 'L6_Y'}, {Cell.MORPHOLOGY: "morph-B"}]}), [1])
npt.assert_equal(_call({Cell.MORPHOLOGY: ['morph-A', 'morph-B']}), [0, 1])
npt.assert_equal(_call({"$and": [{}, {}]}), [0, 1, 2])
npt.assert_equal(_call({"$and": [{}, {Cell.MORPHOLOGY: 'morph-B'}]}), [1])
# same query with a $or operator
npt.assert_equal(_call({"$or": [{Cell.MORPHOLOGY: 'morph-A'},
{Cell.MORPHOLOGY: 'morph-B'}]}), [0, 1])
npt.assert_equal(_call({"$or": [{Cell.MTYPE: 'L6_Y'},
{Cell.MORPHOLOGY: "morph-B"}]}), [1, 2])

npt.assert_equal(_call({"$or": [{}, {}]}), [0, 1, 2])
npt.assert_equal(_call({"$or": [{}, {Cell.MORPHOLOGY: 'morph-B'}]}), [0, 1, 2])
# non destructive operation for queries
query = {"$and": [{"$or": [{Cell.MTYPE: 'L6_Y'}, {Cell.MORPHOLOGY: "morph-B"}]},
{"node_id": [1]}]}
Expand Down

0 comments on commit a5f2136

Please sign in to comment.