Skip to content

temporian.EventSet.add_index #

add_index(indexes: Union[str, List[str]]) -> EventSetOrNode

Adds indexes to an EventSet.

Usage example
>>> a = tp.event_set(
...     timestamps=[1, 2, 1, 0, 1, 1],
...     features={
...         "f1": [1, 1, 1, 2, 2, 2],
...         "f2": [1, 1, 2, 1, 1, 2],
...         "f3": [1, 1, 1, 1, 1, 1]
...     },
... )

>>> # No index
>>> a
indexes: []
features: [('f1', int64), ('f2', int64), ('f3', int64)]
events:
    (6 events):
        timestamps: [0. 1. 1. 1. 1. 2.]
        'f1': [2 1 1 2 2 1]
        'f2': [1 1 2 1 2 1]
        'f3': [1 1 1 1 1 1]
...

>>> # Add only "f1" as index
>>> b = a.add_index("f1")
>>> b
indexes: [('f1', int64)]
features: [('f2', int64), ('f3', int64)]
events:
    f1=1 (3 events):
        timestamps: [1. 1. 2.]
        'f2': [1 2 1]
        'f3': [1 1 1]
    f1=2 (3 events):
        timestamps: [0. 1. 1.]
        'f2': [1 1 2]
        'f3': [1 1 1]
...

>>> # Add "f1" and "f2" as indices
>>> b = a.add_index(["f1", "f2"])
>>> b
indexes: [('f1', int64), ('f2', int64)]
features: [('f3', int64)]
events:
    f1=1 f2=1 (2 events):
        timestamps: [1. 2.]
        'f3': [1 1]
    f1=1 f2=2 (1 events):
        timestamps: [1.]
        'f3': [1]
    f1=2 f2=1 (2 events):
        timestamps: [0. 1.]
        'f3': [1 1]
    f1=2 f2=2 (1 events):
        timestamps: [1.]
        'f3': [1]
...

Parameters:

Name Type Description Default
indexes Union[str, List[str]]

List of feature names (strings) that should be added to the indexes. These feature names should already exist in the input.

required

Returns:

Type Description
EventSetOrNode

EventSet with the extended index.

Raises:

Type Description
KeyError

If any of the specified indexes are not found in the input.