temporian.EventSet.since_last #
since_last(
steps: int = 1,
sampling: Optional[EventSetOrNode] = None,
) -> EventSetOrNode
Computes the amount of time since the last previous timestamp in an
EventSet
.
If a number of steps
is provided, compute elapsed time after moving
back that number of previous events.
Basic example with 1 and 2 steps
>>> a = tp.event_set(timestamps=[1, 5, 8, 8, 9])
>>> # Default: time since previous event
>>> b = a.since_last()
>>> b
indexes: ...
timestamps: [1. 5. 8. 8. 9.]
'since_last': [nan 4. 3. 0. 1.]
...
>>> # Time since 2 previous events
>>> b = a.since_last(steps=2)
>>> b
indexes: ...
timestamps: [1. 5. 8. 8. 9.]
'since_last': [nan nan 7. 3. 1.]
...
If sampling
is provided, the output will correspond to the time elapsed
between each timestamp in sampling
and the latest previous or equal
timestamp in the input.
Example with sampling
>>> a = tp.event_set(timestamps=[1, 4, 5, 7])
>>> b = tp.event_set(timestamps=[-1, 2, 4, 6, 10])
>>> # Time elapsed between each sampling event
>>> # and the latest previous event in a
>>> c = a.since_last(sampling=b)
>>> c
indexes: ...
timestamps: [-1. 2. 4. 6. 10.]
'since_last': [nan 1. 0. 1. 3.]
...
>>> # 2 steps with sampling
>>> c = a.since_last(steps=2, sampling=b)
>>> c
indexes: ...
timestamps: [-1. 2. 4. 6. 10.]
'since_last': [nan nan 3. 2. 5.]
...
Parameters:
Name | Type | Description | Default |
---|---|---|---|
steps |
int
|
Number of previous events to compute elapsed time with. |
1
|
sampling |
Optional[EventSetOrNode]
|
EventSet to use the sampling of. |
None
|
Returns:
Type | Description |
---|---|
EventSetOrNode
|
Resulting EventSet, with same sampling as |