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:

  1. ISO 8601 dates (e.g. 2018-03-09)

  2. 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:

  1. Reduced precision ISO 8601 dates that are missing the day part (e.g. 2018-03)

  2. 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:

  1. Incomplete ambiguous ISO 8601 dates that are missing both the month and day parts (e.g. 2018)

  2. 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:

float

augur.dates.get_numerical_date_from_value(value, fmt, min_max_year=None)
Return type:

Union[float, Tuple[float, float], None]

augur.dates.get_numerical_dates(metadata, fmt, name_col=None, date_col='date', min_max_year=None)
Return type:

Dict[str, Union[float, Tuple[float, float], 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.

Return type:

Tuple[Optional[int], Optional[int], Optional[int]]

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).

Parameters:
  • date (str) – Date string in the format of YYYY-MM-DD

  • ambiguous_by (str) – Field of the date string to test for ambiguity (β€œday”, β€œmonth”, β€œyear”, β€œany”)

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

Submodules