augur.dates package

augur.dates.get_numerical_date_from_value(value, fmt=None, min_max_year=None)
augur.dates.get_numerical_dates(metadata, name_col=None, date_col='date', fmt=None, min_max_year=None)
augur.dates.get_year_month(year, month)
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, treetime
>>> numeric_date("1W") == treetime.utils.numeric_date(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