lilio.calendar_shorthands
ο
Shorthands for calendars, to make generating commonly used calendars a one-liner.
Module Contentsο
- lilio.calendar_shorthands.daily_calendar(anchor: str, length: str = '1d', n_targets: int = 1, n_precursors: int = 0, allow_overlap: bool = False) lilio.calendar.Calendar [source]ο
Instantiate a basic daily calendar with minimal configuration.
Set up a quick calendar revolving around intervals with day-based lengths. The intervals will extend back in time with as many intervals as fit within the cycle time of one year.
- Parameters:
anchor β String in the form β12-31β for December 31st. The first target interval will contain the anchor, while the precursor intervals are built back in time starting at this date.
length β The length of every target and precursor period.
n_targets β integer specifying the number of target intervals in a period.
n_precursors β Sets the maximum number of precursors of the Calendar. If 0, the amount will be determined by how many fit in each anchor year. If a value is provided, the intervals can either only cover part of the year, or extend over multiple years. In case of a large max_lag number where the intervals extend over multiple years, anchor years will be skipped to avoid overlapping intervals. To allow overlapping intervals, use the allow_overlap kwarg.
allow_overlap β Allows intervals to overlap between anchor years, if the max_lag is set to a high enough number that intervals extend over multiple years. False by default, to avoid train/test information leakage.
- Returns:
An instantiated Calendar built according to the input kwarg specifications
Example
Instantiate a calendar counting towards Christmas in 3-days steps.
>>> import lilio >>> calendar = lilio.daily_calendar(anchor='12-25', length="3d", n_precursors=3) >>> calendar Calendar( anchor='12-25', allow_overlap=False, mapping=None, intervals=[ Interval(role='target', length='3d', gap='0d'), Interval(role='precursor', length='3d', gap='0d'), Interval(role='precursor', length='3d', gap='0d'), Interval(role='precursor', length='3d', gap='0d') ] )
- lilio.calendar_shorthands.weekly_calendar(anchor: str, length: str = '1W', n_targets: int = 1, n_precursors: int = 0, allow_overlap: bool = False) lilio.calendar.Calendar [source]ο
Instantiate a basic monthly calendar with minimal configuration.
Set up a quick calendar revolving around intervals with week-based lengths. The precursor intervals will extend back in time with as many intervals as fit within the cycle time of one year (i.e. 52 - n_targets).
Note that the difference between this calendar and the daily_calendar revolves around the use of calendar weeks (Monday - Sunday), instead of 7-day periods.
- Parameters:
anchor β Str in the form of β40Wβ, denoting the week number. The first target interval will contain the anchor, while the precursor intervals are built back in time starting from this week.
length β The length of every precursor and target interval, e.g. β2Wβ.
n_targets β integer specifying the number of target intervals in a period.
n_precursors β Sets the maximum number of precursors of the Calendar. If 0, the amount will be determined by how many fit in each anchor year. If a value is provided, the intervals can either only cover part of the year, or extend over multiple years. In case of a large max_lag number where the intervals extend over multiple years, anchor years will be skipped to avoid overlapping intervals. To allow overlapping intervals, use the allow_overlap kwarg.
allow_overlap β Allows intervals to overlap between anchor years, if the max_lag is set to a high enough number that intervals extend over multiple years. False by default, to avoid train/test information leakage.
- Returns:
An instantiated Calendar built according to the input kwarg specifications
Example
Instantiate a calendar counting down the quarters (3 month periods) from december.
>>> import lilio >>> calendar = lilio.weekly_calendar(anchor="W40", length="1W", n_precursors=2) >>> calendar Calendar( anchor='W40-1', allow_overlap=False, mapping=None, intervals=[ Interval(role='target', length='1W', gap='0d'), Interval(role='precursor', length='1W', gap='0d'), Interval(role='precursor', length='1W', gap='0d') ] )
- lilio.calendar_shorthands.monthly_calendar(anchor: str, length: str = '1M', n_targets: int = 1, n_precursors: int = 0, allow_overlap: bool = False) lilio.calendar.Calendar [source]ο
Instantiate a basic monthly calendar with minimal configuration.
Set up a quick calendar revolving around intervals with month-based lengths. The intervals will extend back in time with as many intervals as fit within the cycle time of one year.
- Parameters:
anchor β Str in the form βJanuaryβ or βJanβ. he first target interval will contain the anchor, while the precursor intervals are built back in time starting at this Month.
length β The length of every target and precursor period, in the form β1Mβ, β2Mβ, etc.
n_targets β integer specifying the number of target intervals in a period.
n_precursors β Sets the maximum number of precursors of the Calendar. If 0, the amount will be determined by how many fit in each anchor year. If a value is provided, the intervals can either only cover part of the year, or extend over multiple years. In case of a large max_lag number where the intervals extend over multiple years, anchor years will be skipped to avoid overlapping intervals. To allow overlapping intervals, use the allow_overlap kwarg.
allow_overlap β Allows intervals to overlap between anchor years, if the max_lag is set to a high enough number that intervals extend over multiple years. False by default, to avoid train/test information leakage.
- Returns:
An instantiated Calendar built according to the input kwarg specifications
Example
Instantiate a calendar counting down the quarters (3 month periods) from december.
>>> import lilio >>> calendar = lilio.monthly_calendar(anchor='Dec', length="3M") >>> calendar Calendar( anchor='12', allow_overlap=False, mapping=None, intervals=[ Interval(role='target', length='3M', gap='0d'), Interval(role='precursor', length='3M', gap='0d'), Interval(role='precursor', length='3M', gap='0d'), Interval(role='precursor', length='3M', gap='0d') ] )