Skip to content

Commit

Permalink
Fix computation of union of empty and nonempty Selector instances.
Browse files Browse the repository at this point in the history
  • Loading branch information
lebedov committed Feb 12, 2015
1 parent 4c73c1f commit d39af3b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
8 changes: 6 additions & 2 deletions neurokernel/plsel.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,12 @@ def union(cls, *sels):
out = cls('')
tmp = set()
for s in sels:
tmp = tmp.union(s.expanded)
out._expanded = tuple(sorted(tmp))
if s.nonempty:
tmp = tmp.union(s.expanded)
if tmp:
out._expanded = tuple(sorted(tmp))
else:
out._expanded = ((),)
try:
out._max_levels = max([s.max_levels for s in sels if s.nonempty])
except ValueError:
Expand Down
9 changes: 9 additions & 0 deletions tests/test_plsel.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,15 @@ def test_selector_union_nonempty(self):
assert c.max_levels == 2
assert c.str == '/x/0,/x/1,/x/2,/x/3,/x/4'

def test_selector_union_empty_nonempty(self):
a = Selector('')
b = Selector('/x[0:3]')
c = Selector.union(a, b)
assert len(c) == 3
assert c.expanded == (('x', 0), ('x', 1), ('x', 2))
assert c.max_levels == 2
assert c.str == '/x/0,/x/1,/x/2'

class test_path_like_selector(TestCase):
def setUp(self):
self.df = df.copy()
Expand Down

0 comments on commit d39af3b

Please sign in to comment.