temporian.EventSet.tick_calendar #
tick_calendar(
second: Optional[Union[int, Literal["*"]]] = None,
minute: Optional[Union[int, Literal["*"]]] = None,
hour: Optional[Union[int, Literal["*"]]] = None,
mday: Optional[Union[int, Literal["*"]]] = None,
month: Optional[Union[int, Literal["*"]]] = None,
wday: Optional[Union[int, Literal["*"]]] = None,
) -> EventSetOrNode
Generates events periodically at fixed times or dates e.g. each month.
Events are generated in the range of the input
EventSet
independently for each index.
The usability is inspired in the crontab format, where arguments can
take a value of '*'
to tick at all values, or a fixed integer to
tick only at that precise value.
Non-specified values (None
), are set to '*'
if a finer
resolution argument is specified, or fixed to the first valid value if
a lower resolution is specified. For example, setting only
tick_calendar(hour='*')
is equivalent to:
tick_calendar(second=0, minute=0, hour='*', mday='*', month='*')
, resulting in one tick at every exact hour of every day/month/year in
the input guide range.
The datetime timezone is always assumed to be UTC.
Examples:
>>> # Every day (at 00:00:00) in the period (exactly one year)
>>> a = tp.event_set(timestamps=["2021-01-01", "2021-12-31 23:59:59"])
>>> b = a.tick_calendar(hour=0)
>>> b
indexes: ...
events:
(365 events):
timestamps: [...]
...
>>> # Every day at 2:30am
>>> b = a.tick_calendar(hour=2, minute=30)
>>> tp.glue(b.calendar_hour(), b.calendar_minute())
indexes: ...
events:
(365 events):
timestamps: [...]
'calendar_hour': [2 2 2 ... 2 2 2]
'calendar_minute': [30 30 30 ... 30 30 30]
...
>>> # Day 5 of every month (at 00:00)
>>> b = a.tick_calendar(mday=5)
>>> b.calendar_day_of_month()
indexes: ...
events:
(12 events):
timestamps: [...]
'calendar_day_of_month': [5 5 5 ... 5 5 5]
...
>>> # 1st of February of every year
>>> a = tp.event_set(timestamps=["2020-01-01", "2021-12-31"])
>>> b = a.tick_calendar(month=2)
>>> tp.glue(b.calendar_day_of_month(), b.calendar_month())
indexes: ...
events:
(2 events):
timestamps: [...]
'calendar_day_of_month': [1 1]
'calendar_month': [2 2]
...
>>> # Every second in the period (2 hours -> 7200 seconds)
>>> a = tp.event_set(timestamps=["2020-01-01 00:00:00",
... "2020-01-01 01:59:59"])
>>> b = a.tick_calendar(second='*')
>>> b
indexes: ...
events:
(7200 events):
timestamps: [...]
...
>>> # Every second of the minute 30 of every hour (00:30 and 01:30)
>>> a = tp.event_set(timestamps=["2020-01-01 00:00",
... "2020-01-01 02:00"])
>>> b = a.tick_calendar(second='*', minute=30)
>>> b
indexes: ...
events:
(120 events):
timestamps: [...]
...
>>> # Not allowed: intermediate arguments (minute, hour) not specified
>>> b = a.tick_calendar(second=1, mday=1) # ambiguous meaning
Traceback (most recent call last):
...
ValueError: Can't set argument to None because previous and
following arguments were specified. Set to '*' or an integer ...
Parameters:
Name | Type | Description | Default |
---|---|---|---|
second |
Optional[Union[int, Literal['*']]]
|
'*' (any second), None (auto) or number in range |
None
|
minute |
Optional[Union[int, Literal['*']]]
|
'*' (any minute), None (auto) or number in range |
None
|
hour |
Optional[Union[int, Literal['*']]]
|
'*' (any hour), None (auto), or number in range |
None
|
mday |
Optional[Union[int, Literal['*']]]
|
'*' (any day), None (auto) or number in range |
None
|
month |
Optional[Union[int, Literal['*']]]
|
'*' (any month), None (auto) or number in range |
None
|
wday |
Optional[Union[int, Literal['*']]]
|
'*' (any day), None (auto) or number in range |
None
|
Returns:
Type | Description |
---|---|
EventSetOrNode
|
A feature-less EventSet with timestamps at specified interval. |