Skip to content

Commit

Permalink
simplifies type handling, removes invalid filepath testing
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisKeefe committed May 20, 2020
1 parent c4d7ed9 commit 0f6dd11
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 36 deletions.
6 changes: 0 additions & 6 deletions q2_diversity_lib/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
# ----------------------------------------------------------------------------

from inspect import signature
import os

import numpy as np
from decorator import decorator
Expand Down Expand Up @@ -40,13 +39,8 @@ def _disallow_empty_tables(some_function, *args, **kwargs):
if table is None:
raise TypeError("The wrapped function has no parameter 'table'")

# TODO: It is not possible for a string passed to the framework to make it here
# TODO: if table is an instance of BIOM, is it possible for it to have an
# invalid filepath?
if isinstance(table, BIOMV210Format):
table = str(table)
# if not os.path.exists(table):
# raise ValueError(f'Invalid file path: {table} does not exist')
table_obj = load_table(table)
elif isinstance(table, bTable):
table_obj = table
Expand Down
24 changes: 2 additions & 22 deletions q2_diversity_lib/beta.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,7 @@ def unweighted_unifrac(table: BIOMV210Format,
bypass_tips: bool = False) -> skbio.DistanceMatrix:
f = unifrac.unweighted

# TODO: is there ever a scenario in which an str will actually reach
# this function? If not, torch this logic, and remove str handling from
# _disallow_empty_tables
if type(table) == str:
table_fp = table
elif type(table) == BIOMV210Format:
table_fp = table.open().filename
else:
raise TypeError("Invalid table: must be BIOMV210Format or str.")

return f(table_fp, str(phylogeny), threads=n_jobs,
return f(str(table), str(phylogeny), threads=n_jobs,
variance_adjusted=False, bypass_tips=bypass_tips)


Expand All @@ -80,15 +70,5 @@ def weighted_unifrac(table: BIOMV210Format,
bypass_tips: bool = False) -> skbio.DistanceMatrix:
f = unifrac.weighted_unnormalized

# TODO: is there ever a scenario in which an str will actually reach
# this function? If not, torch this logic, and remove str handling from
# _disallow_empty_tables, and revert return from table_fp to table.open...
if type(table) == str:
table_fp = table
elif type(table) == BIOMV210Format:
table_fp = table.open().filename
else:
raise TypeError("Invalid table: must be BIOMV210Format or str.")

return f(table_fp, str(phylogeny), threads=n_jobs,
return f(str(table), str(phylogeny), threads=n_jobs,
variance_adjusted=False, bypass_tips=bypass_tips)
8 changes: 0 additions & 8 deletions q2_diversity_lib/tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ def setUp(self):
self.valid_table_fp = self.get_data_path('crawford.biom')
self.valid_table_as_BIOMV210Format = \
BIOMV210Format(self.valid_table_fp, mode='r')
# TODO: remove?
# self.invalid_table_fp = 'invalid_path_name.baaad'
self.not_a_table_fp = self.get_data_path('crawford.nwk')
self.invalid_view_type = NewickFormat(self.not_a_table_fp, mode='r')

Expand Down Expand Up @@ -66,12 +64,6 @@ def test_wrapped_function_has_no_table_param(self):
with self.assertRaisesRegex(TypeError, "no parameter.*table"):
self.function_without_table_param()

# TODO: remove?
# def test_passed_invalid_file_path(self):
# with self.assertRaisesRegex(
# ValueError, "file path.*invalid_path_name.baaad"):
# self.function_with_table_param(table=self.invalid_table_fp)

def test_passed_invalid_view_type(self):
with self.assertRaisesRegex(
ValueError, "Invalid view type.*Newick"):
Expand Down

0 comments on commit 0f6dd11

Please sign in to comment.