Skip to content

Commit

Permalink
TST: Adding scenario where intersection yield empty tree, table, meta…
Browse files Browse the repository at this point in the history
…data
  • Loading branch information
mortonjt committed Aug 18, 2016
1 parent 77898f6 commit ed81fc6
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
7 changes: 7 additions & 0 deletions gneiss/_formula.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ def _intersect_of_table_metadata_tree(table, metadata, tree):
_table, _tree = match_tips(_table, tree)
non_tips_no_name = [(n.name is None) for n in _tree.levelorder()
if not n.is_tip()]
if len(non_tips_no_name) == 0:
raise ValueError('There are no internal nodes in `tree` after'
'intersection with `table`.')

if len(_table.index) == 0:
raise ValueError('There are no internal nodes in `table` after '
'intersection with `metadata`.')

if any(non_tips_no_name):
_tree = rename_internal_nodes(_tree)
Expand Down
40 changes: 38 additions & 2 deletions gneiss/tests/test_formula.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,44 @@ def test_ols_immutable(self):
self.assertEqual(str(table), str(exp_table))
self.assertEqual(str(exp_tree), str(tree))

def test_ols_empty(self):
pass
def test_ols_empty_table(self):
A = np.array # aliasing for the sake of pep8
table = pd.DataFrame({
's1': ilr_inv(A([1., 1.])),
's2': ilr_inv(A([1., 2.])),
's3': ilr_inv(A([1., 3.])),
's4': ilr_inv(A([1., 4.])),
's5': ilr_inv(A([1., 5.])),
's6': ilr_inv(A([1., 5.]))},
index=['x', 'y', 'z']).T

tree = TreeNode.read(['((c,d),(b,a)Y2)Y1;'])
metadata = pd.DataFrame({
'lame': [1, 1, 1, 1, 1],
'real': [1, 2, 3, 4, 5]
}, index=['s1', 's2', 's3', 's4', 's5'])
with self.assertRaises(ValueError):
ols('real + lame', table, metadata, tree)

def test_ols_empty_metadata(self):
A = np.array # aliasing for the sake of pep8
table = pd.DataFrame({
'k1': ilr_inv(A([1., 1.])),
'k2': ilr_inv(A([1., 2.])),
'k3': ilr_inv(A([1., 3.])),
'k4': ilr_inv(A([1., 4.])),
'k5': ilr_inv(A([1., 5.])),
'k6': ilr_inv(A([1., 5.]))},
index=['a', 'b', 'c']).T

tree = TreeNode.read(['((c,d),(b,a)Y2)Y1;'])
metadata = pd.DataFrame({
'lame': [1, 1, 1, 1, 1],
'real': [1, 2, 3, 4, 5]
}, index=['s1', 's2', 's3', 's4', 's5'])
with self.assertRaises(ValueError):
ols('real + lame', table, metadata, tree)


if __name__ == '__main__':
unittest.main()

0 comments on commit ed81fc6

Please sign in to comment.