Skip to content

temporian.EventSet.cumsum #

cumsum(
    sampling: Optional[EventSetOrNode] = None,
) -> EventSetOrNode

Computes the cumulative sum of values over each feature in an EventSet.

Foreach timestamp, calculate the sum of the feature from the beginning. Shorthand for moving_sum(event, window_length=np.inf).

Missing (NaN) values are not accounted for. The output will be NaN until the input contains at least one numeric value.

If sampling is specified or window_length is an EventSet, the moving window is sampled at each timestamp in them, else it is sampled on the input's.

Example
>>> a = tp.event_set(
...     timestamps=[0, 1, 2, 5, 6, 7],
...     features={"value": [np.nan, 1, 5, 10, 15, 20]},
... )

>>> b = a.cumsum()
>>> b
indexes: ...
    (6 events):
        timestamps: [0. 1. 2. 5. 6. 7.]
        'value': [ 0. 1.  6.  16.  31.  51.]
...
Examples with sampling
>>> a = tp.event_set(
...     timestamps=[0, 1, 2, 5, 6, 7],
...     features={"value": [np.nan, 1, 5, 10, 15, 20]},
... )

>>> # Cumulative sum at 5 and 10
>>> b = tp.event_set(timestamps=[5, 10])
>>> c = a.cumsum(sampling=b)
>>> c
indexes: ...
    (2 events):
        timestamps: [ 5. 10.]
        'value': [16. 51.]
...

>>> # Sum all values in the EventSet
>>> c = a.cumsum(sampling=a.end())
>>> c
indexes: ...
    (1 events):
        timestamps: [7.]
        'value': [51.]
...

Parameters:

Name Type Description Default
sampling Optional[EventSetOrNode]

Timestamps to sample the sliding window's value at. If not provided, timestamps in the input are used.

None

Returns:

Type Description
EventSetOrNode

Cumulative sum of each feature.