Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filter: Support relative dates for --min-date and --max-date #740

Merged
merged 5 commits into from
Apr 11, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions augur/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1735,6 +1735,10 @@ def numeric_date(date):
except (ValueError, isodate.ISO8601Error):
pass

# This currently doesn't get exposed since argparse raises a SystemExit on invalid arguments.
# TODO: find a way to provide better errors for invalid dates.
raise ValueError(f"Unable to determine date from {date}.")
victorlin marked this conversation as resolved.
Show resolved Hide resolved


def calculate_sequences_per_group(target_max_value, counts_per_group, allow_probabilistic=True):
"""Calculate the number of sequences per group for a given maximum number of
Expand Down
16 changes: 16 additions & 0 deletions tests/test_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,3 +356,19 @@ def test_filter_relative_dates(self, tmpdir, argparser, argparse_params, metadat
with open(out_fn) as f:
output_sorted = sorted(line.rstrip() for line in f)
assert output_sorted == output_sorted_expected

@freeze_time("2020-03-25")
@pytest.mark.parametrize(
"argparse_params",
[
"--max-date 3000Y",
"--max-date invalid",
],
)
def test_filter_relative_dates_error(self, tmpdir, argparser, argparse_params):
"""Test that invalid dates fail"""
out_fn = str(tmpdir / "filtered.txt")
meta_fn = write_metadata(tmpdir, (("strain","date"),
("SEQ_1","2020-03-23")))
with pytest.raises(SystemExit):
argparser(f'--metadata {meta_fn} --output-strains {out_fn} {argparse_params}')