Skip to content

temporian.EventSet.where #

where(
    on_true: Union[EventSetOrNode, Any],
    on_false: Union[EventSetOrNode, Any],
) -> EventSetOrNode

Choose event-wise feature values from on_true or on_false depending on the boolean value of self.

Given an input EventSet with a single boolean feature, create a new one using the same sampling, and choosing values from on_true when the input is True, otherwise take value from on_false.

Both on_true and on_false can be single values or EventSets with the same sampling as the boolean input and one single feature. In any case, both sources must have the same data type, or be explicitly casted to the same type beforehand.

Example with single values
>>> a = tp.event_set(timestamps=[5, 9, 9],
...                  features={'f': [True, True, False]})
>>> b = a.where(on_true='hello', on_false='goodbye')
>>> b
indexes: ...
events:
    (3 events):
        timestamps: [5. 9. 9.]
        'f': [b'hello' b'hello' b'goodbye']
...
Example with EventSets
>>> a = tp.event_set(timestamps=[5, 9, 10],
...                  features={'condition': [True, True, False],
...                            'yes': [1, 2, 3],
...                            'no': [-1, -2, -3]})

>>> b = a['condition'].where(a['yes'], a['no'])
>>> b
indexes: ...
events:
    (3 events):
        timestamps: [ 5. 9. 10.]
        'condition': [ 1 2 -3]
...
Example setting to NaN based on condition
>>> a = tp.event_set(timestamps=[5, 6, 7, 8, 9],
...                  features={'f': [1, 2, -3, -4, 5]})

>>> # Set values < 0 to nan (cast to float to support nan)
>>> b = (a['f'] >= 0).where(a['f'].cast(float), np.nan)
>>> b
indexes: ...
events:
    (5 events):
        timestamps: [5. 6. 7. 8. 9.]
        'f': [ 1. 2. nan nan 5.]
...

Parameters:

Name Type Description Default
on_true Union[EventSetOrNode, Any]

Source of values from when the condition is True.

required
on_false Union[EventSetOrNode, Any]

Source of values from when the condition is False.

required

Returns:

Type Description
EventSetOrNode

EventSet with a single feature and same sampling as input.