Skip to content

temporian.EventSet.drop_index #

drop_index(
    indexes: Optional[Union[str, List[str]]] = None,
    keep: bool = True,
) -> EventSetOrNode

Removes indexes from 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]
...     },
...     indexes=["f1", "f2"]
... )

>>> # Both f1 and f2 are indices
>>> a
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]
...

>>> # Drop "f2", remove it from features
>>> b = a.drop_index("f2", keep=False)
>>> b
indexes: [('f1', int64)]
features: [('f3', int64)]
events:
    f1=1 (3 events):
        timestamps: [1. 1. 2.]
        'f3': [1 1 1]
    f1=2 (3 events):
        timestamps: [0. 1. 1.]
        'f3': [1 1 1]
...

>>> # Drop both indices, keep them as features
>>> b = a.drop_index(["f2", "f1"])
>>> b
indexes: []
features: [('f3', int64), ('f2', int64), ('f1', int64)]
events:
    (6 events):
        timestamps: [0. 1. 1. 1. 1. 2.]
        'f3': [1 1 1 1 1 1]
        'f2': [2 1 1 2 2 1]
        'f1': [1 2 1 2 1 1]
...

Parameters:

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

Index column(s) to be removed from the input. This can be a single column name (str) or a list of column names (List[str]). If not specified or set to None, all indexes in the input will be removed. Defaults to None.

None
keep bool

Flag indicating whether the removed indexes should be kept as features in the output EventSet. Defaults to True.

True

Returns:

Type Description
EventSetOrNode

EventSet with the specified indexes removed. If keep is set to

EventSetOrNode

True, the removed indexes will be included as features in it.

Raises:

Type Description
ValueError

If an empty list is provided as the index_names argument.

KeyError

If any of the specified index_names are missing from the input's index.

ValueError

If a feature name coming from the indexes already exists in the input, and the keep flag is set to True.