Skip to content

Commit d504499

Browse files
committed
Consider XXXX-XX-XX as missing date
Previously, this was considered an ambiguous date with a range of '[0001-01-01, present]'. That may be somewhat correct, but it has the side effect of passing min/max date filters. Other missing dates such as empty string are dropped by those date filters, and it seems more reasonable to consider XXXX-XX-XX the same way.
1 parent 6c031bf commit d504499

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

augur/dates/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,12 @@ def is_date_ambiguous(date, ambiguous_by):
161161
Note that this can support any date format, not just YYYY-MM-DD.
162162
"""
163163

164+
RE_AUGUR_MISSING_DATE = re.compile(r'^XXXX-XX-XX$')
165+
"""
166+
Matches an Augur-style ambiguous date with all parts masked.
167+
This only supports YYYY-MM-DD format.
168+
"""
169+
164170
RE_DATE_RANGE = re.compile(r'^\d{4}-\d{2}-\d{2}/\d{4}-\d{2}-\d{2}$')
165171
"""
166172
Matches a date range in YYYY-MM-DD/YYYY-MM-DD format.
@@ -171,6 +177,10 @@ def is_date_ambiguous(date, ambiguous_by):
171177
def get_numerical_date_from_value(value, fmt, min_max_year=None) -> Union[float, Tuple[float, float], None]:
172178
value = str(value)
173179

180+
# Check if value is a missing date.
181+
if RE_AUGUR_MISSING_DATE.match(value):
182+
return None
183+
174184
# Check if value is an exact date in the specified format (fmt).
175185
try:
176186
return date_to_numeric(datetime.datetime.strptime(value, fmt))
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
Setup
2+
3+
$ source "$TESTDIR"/_setup.sh
4+
5+
Create metadata TSV file with two date values that should be functionally equivalent.
6+
7+
$ cat >metadata.tsv <<~~
8+
> strain date
9+
> SEQ_1
10+
> SEQ_2 XXXX-XX-XX
11+
> ~~
12+
13+
BUG: SEQ_2 passes for --min-date and --max-date.
14+
15+
$ ${AUGUR} filter \
16+
> --metadata metadata.tsv \
17+
> --min-date 2025 \
18+
> --output-strains filtered_strains.txt
19+
2 strains were dropped during filtering
20+
2 were dropped because they were earlier than 2025.0 or missing a date
21+
ERROR: All samples have been dropped! Check filter rules and metadata file format.
22+
[2]
23+
24+
$ ${AUGUR} filter \
25+
> --metadata metadata.tsv \
26+
> --max-date 2025 \
27+
> --output-strains filtered_strains.txt
28+
2 strains were dropped during filtering
29+
2 were dropped because they were later than 2025.0 or missing a date
30+
ERROR: All samples have been dropped! Check filter rules and metadata file format.
31+
[2]

0 commit comments

Comments
 (0)