pipeline.src.shared_tasks.dates

Classes

TimeUnit

Create a collection of name/value pairs.

Functions

get_utcnow()

Task version of datetime.utcnow

date_trunc(d, unit)

get_current_year(→ int)

Returns current year

get_timezone_aware_utcnow()

make_timedelta(→ datetime.timedelta)

Task version of datetime.timedelta

make_relativedelta(→ datetime.timedelta)

Task version of dateutil.relativedelta

make_periods(→ List[src.helpers.dates.Period])

prefect.Task version of the function src.helpers.dates.make_periods,

Module Contents

class pipeline.src.shared_tasks.dates.TimeUnit(*args, **kwds)[source]

Bases: enum.Enum

Create a collection of name/value pairs.

Example enumeration:

>>> class Color(Enum):
...     RED = 1
...     BLUE = 2
...     GREEN = 3

Access them by:

  • attribute access:

>>> Color.RED
<Color.RED: 1>
  • value lookup:

>>> Color(1)
<Color.RED: 1>
  • name lookup:

>>> Color['RED']
<Color.RED: 1>

Enumerations can be iterated over, and know how many members they have:

>>> len(Color)
3
>>> list(Color)
[<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]

Methods can be added to enumerations, and members can have their own attributes – see the documentation for details.

YEAR = 'YEAR'[source]
MONTH = 'MONTH'[source]
DAY = 'DAY'[source]
HOUR = 'HOUR'[source]
MINUTE = 'MINUTE'[source]
SECOND = 'SECOND'[source]
pipeline.src.shared_tasks.dates.get_utcnow()[source]

Task version of datetime.utcnow

pipeline.src.shared_tasks.dates.date_trunc(d: datetime.datetime, unit: str)[source]
pipeline.src.shared_tasks.dates.get_current_year() int[source]

Returns current year

pipeline.src.shared_tasks.dates.get_timezone_aware_utcnow()[source]
pipeline.src.shared_tasks.dates.make_timedelta(**kwargs) datetime.timedelta[source]

Task version of datetime.timedelta

pipeline.src.shared_tasks.dates.make_relativedelta(**kwargs) datetime.timedelta[source]

Task version of dateutil.relativedelta

pipeline.src.shared_tasks.dates.make_periods(start_hours_ago: int, end_hours_ago: int, minutes_per_chunk: int, chunk_overlap_minutes: int) List[src.helpers.dates.Period][source]

prefect.Task version of the function src.helpers.dates.make_periods, with the difference that start and end dates are to be given as a number of hours from the current date (instead of datetime objects), and chunk duration and overlap are to be given as a number of minutes (instead of timedelta objects). This is to accomodate for the fact that Prefect flows’ parameters must be JSON-serializable, and datetime and timedelta are not, by default.

src.helpers.dates.make_periods is recursive, hence the construction as a python function first and not directly as Prefect Task.

See src.helpers.dates.make_periods for help.