Skip to content

Commit

Permalink
Issue 948 (#959)
Browse files Browse the repository at this point in the history
* TST: regression test for issue #948

* BUG: fixes issue #948

* DOC: changelog mention for issue #948
  • Loading branch information
wasade authored May 2, 2024
1 parent 29163c6 commit 7182747
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Bug fixes:
* Allow `Table.to_json` to properly handle numpy types in metadata, see issue [#886](https://github.com/biocore/biom-format/issues/886)
* Do not modify IDs in place in the presence of duplicate relabels, see issue [#892](https://github.com/biocore/biom-format/issues/892)
* Catch an edge case where a failured ID update in place would actually change IDs, see issue [#892](https://github.com/biocore/biom-format/issues/892)
* Fixed an edge case on in `align_tree` when a feature was empty, see issue [#948](https://github.com/biocore/biom-format/issues/948)

New features:

Expand Down
1 change: 0 additions & 1 deletion biom/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -1073,7 +1073,6 @@ def align_tree(self, tree, axis='observation'):
raise TableException("No common ids between table and tree.")
_tree = tree.shear(names=common_tips)
_table = self.filter(common_tips, axis=axis, inplace=False)
_table.remove_empty()
_tree.prune()
order = [n.name for n in _tree.tips()]
_table = _table.sort_order(order, axis=axis)
Expand Down
15 changes: 15 additions & 0 deletions biom/tests/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -2013,6 +2013,21 @@ def test_align_to_dataframe_samples_no_common_ids(self):
with self.assertRaises(TableException):
table.align_to_dataframe(metadata)

@pytest.mark.skipif(not HAVE_SKBIO, reason="skbio not installed")
def test_align_tree_issue_948(self):
table = Table(np.array([[0, 0, 0, 0],
[2, 3, 4, 4],
[5, 5, 3, 3],
[0, 0, 0, 1]]).T,
['a', 'b', 'c', 'd'],
['s1', 's2', 's3', 's4'])
tree = skbio.TreeNode.read(["(a,b,c,d)r;"])
exp_tree = tree
exp_table = table.copy()
res_table, res_tree = table.align_tree(tree)
self.assertEqual(res_table, exp_table)
self.assertEqual(str(exp_tree), str(res_tree))

@pytest.mark.skipif(not HAVE_SKBIO, reason="skbio not installed")
def test_align_tree_intersect_tips(self):
# there are less tree tips than observations
Expand Down

0 comments on commit 7182747

Please sign in to comment.