augur.dates packageο
- augur.dates.RE_AUGUR_AMBIGUOUS_DATE = re.compile('.*XX.*')ο
Matches an Augur-style ambiguous date with βXXβ used to mask unknown parts of the date. Note that this can support any date format, not just YYYY-MM-DD.
- augur.dates.RE_NUMERIC_DATE = re.compile('^-*\\d+\\.\\d+$')ο
Matches floats (e.g. 2018.0, -2018.0). Note that a year-only value is treated as incomplete ambiguous and must be non-negative (see
RE_YEAR_ONLY
).
- augur.dates.RE_YEAR_MONTH_DAY = re.compile('^\\d+-\\d+-\\d+$')ο
Matches:
ISO 8601 dates (e.g. 2018-03-09)
Other dates in <year>-<month>-<day> format (e.g. 2018-3-9)
Note: This matches out of bounds dates such as 2018-03-32. Those should be further validated by date conversion functions.
- augur.dates.RE_YEAR_MONTH_ONLY = re.compile('^\\d+-\\d+$')ο
Matches:
Reduced precision ISO 8601 dates that are missing the day part (e.g. 2018-03)
Other dates in <year>-<month> format (e.g. 2018-3)
Note: This matches out of bounds dates such as 2018-13. Those should be further validated by date conversion functions.
- augur.dates.RE_YEAR_ONLY = re.compile('^\\d+$')ο
Matches:
Incomplete ambiguous ISO 8601 dates that are missing both the month and day parts (e.g. 2018)
Other positive integers (e.g. 1, 123, 12345)
- augur.dates.date_to_numeric(date)ο
Wrapper around treetime.utils.numeric_date that ensures a float is returned.
- Return type:
- augur.dates.get_numerical_date_from_value(value, fmt, min_max_year=None)ο
- augur.dates.get_numerical_dates(metadata, fmt, name_col=None, date_col='date', min_max_year=None)ο
- augur.dates.get_year_month(year, month)ο
- augur.dates.get_year_month_day(value)ο
Extract year, month, and day from a date value.
Individual date components can be None if unresolvable.
- augur.dates.get_year_week(year, month, day)ο
- augur.dates.is_date_ambiguous(date, ambiguous_by)ο
Returns whether a given date string in the format of YYYY-MM-DD is ambiguous by a given part of the date (e.g., day, month, year, or any parts).
- augur.dates.numeric_date(date)ο
Converts the given date string to a
float
.date may be given as: 1. A string or float (number) with year as the integer part 2. A string in the YYYY-MM-DD (ISO 8601) syntax 3. A string representing a relative date (duration before datetime.date.today())
Examples
>>> numeric_date("2020.42") 2020.42 >>> numeric_date("2020-06-04") 2020.42486... >>> import datetime, isodate >>> numeric_date("1W") == date_to_numeric(datetime.date.today() - isodate.parse_duration("P1W")) True
- augur.dates.numeric_date_type(date)ο
Wraps numeric_date() for argparse usage.
This raises an ArgumentTypeError from InvalidDateFormat exceptions, otherwise the custom exception message wonβt be shown in console output due to: https://github.com/python/cpython/blob/5c4d1f6e0e192653560ae2941a6677fbf4fbd1f2/Lib/argparse.py#L2503-L2513