Skip to content

Commit

Permalink
implement force in loading
Browse files Browse the repository at this point in the history
  • Loading branch information
ctb committed Aug 25, 2022
1 parent ca2ab8b commit 7a655cd
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/sourmash/tax/tax_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,8 @@ def _save_csv(self, fp):
@classmethod
def load(cls, locations, **kwargs):
"Load one or more taxonomies from the given location(s)"
force = kwargs.get('force', False)

if isinstance(locations, str):
raise TypeError("'locations' should be a list, not a string")

Expand All @@ -1034,12 +1036,14 @@ def load(cls, locations, **kwargs):
loaded = True
except (ValueError, csv.Error) as exc:
# for the last loader, just pass along ValueError...
raise ValueError(f"cannot read taxonomy assignments from '{location}': {str(exc)}")
if not force:
raise ValueError(f"cannot read taxonomy assignments from '{location}': {str(exc)}")

# nothing loaded, goodbye!
if not loaded:
if not loaded and not force:
raise ValueError(f"cannot read taxonomy assignments from '{location}'")

tax_assign.add(this_tax_assign)
if loaded:
tax_assign.add(this_tax_assign)

return tax_assign

0 comments on commit 7a655cd

Please sign in to comment.