Skip to content

Commit

Permalink
BUG: ignore_none was ignored, thanks @antgonza!
Browse files Browse the repository at this point in the history
  • Loading branch information
wasade committed May 10, 2024
1 parent dde0378 commit ddd6675
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion biom/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -2488,7 +2488,7 @@ def part_f(i, m):
for vals, id_, md in self.iter(dense=False, axis=axis):
part = part_f(id_, md)

if part is None:
if ignore_none and part is None:
continue

# try to make it hashable...
Expand Down
16 changes: 15 additions & 1 deletion biom/tests/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -4309,7 +4309,7 @@ def test_partition_remove_empty(self):
False: Table(np.array([[1, 2]]), ['O1', ], ['S2', 'S3'])}
self.assertEqual(obs, exp)

def test_partition_ignore_none(self):
def test_partition_ignore_none_true(self):
t = Table(np.array([[0, 1, 2],
[3, 0, 0],
[4, 0, 0]]),
Expand All @@ -4321,6 +4321,20 @@ def test_partition_ignore_none(self):
['O1', 'O2', 'O3'], ['S1', ])}
self.assertEqual(obs, exp)

def test_partition_ignore_none_false(self):
t = Table(np.array([[0, 1, 2],
[3, 0, 0],
[4, 0, 0]]),
['O1', 'O2', 'O3'],
['S1', 'S2', 'S3'])
part_f = lambda i, m: True if i == 'S1' else None # noqa
obs = dict(t.partition(part_f, ignore_none=False))
exp = {True: Table(np.array([[0, ], [3, ], [4, ]]),
['O1', 'O2', 'O3'], ['S1', ]),
None: Table(np.array([[1, 2], [0, 0], [0, 0]]),
['O1', 'O2', 'O3'], ['S2', 'S3'])}
self.assertEqual(obs, exp)

def test_partition_dict_ids_to_groups(self):
t = Table(np.array([[0, 1, 2],
[3, 0, 0],
Expand Down

0 comments on commit ddd6675

Please sign in to comment.