Skip to content

temporian.EventSet.filter #

filter(
    condition: Optional[EventSetOrNode] = None,
) -> EventSetOrNode

Filters out events in an EventSet for which a condition is false.

Each timestamp in the input is only kept if the corresponding value for that timestamp in condition is True.

the input and condition must have the same sampling, and condition must have one single feature, of boolean type.

filter(x) is equivalent to filter(x,x). filter(x) can be used to convert a boolean mask into a timestamps.

Usage example
>>> a = tp.event_set(
...     timestamps=[0, 1, 5, 6],
...     features={"f1": [0, 10, 50, 60], "f2": [50, 100, 500, 600]},
... )

>>> # Example boolean condition
>>> condition = a["f1"] > 20
>>> condition
indexes: ...
        timestamps: [0. 1. 5. 6.]
        'f1': [False False  True  True]
...

>>> # Filter only True timestamps
>>> filtered = a.filter(condition)
>>> filtered
indexes: ...
        timestamps: [5. 6.]
        'f1': [50 60]
        'f2': [500 600]
...

Parameters:

Name Type Description Default
condition Optional[EventSetOrNode]

EventSet with a single boolean feature.

None

Returns:

Type Description
EventSetOrNode

Filtered EventSet.