temporian.combine #
combine(
*inputs: EventSetOrNode,
how: Union[str, How] = How.outer
) -> EventSetOrNode
Combines events from multiple EventSets
together.
Input events must have the same features (i.e. same feature names and dtypes) and index schemas (i.e. same index names and dtypes).
Combine is different from glue
and join
, since those append together
different features.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*inputs |
EventSetOrNode
|
EventSets to combine their events. |
()
|
how |
Union[str, How]
|
Whether to use the indexes from "outer" (union of all inputs' index values), "inner" (only those present in all inputs) or "left" (only use index values from the first input). |
outer
|
Basic example:
```python
>>> a = tp.event_set(timestamps=[0, 1, 3],
... features={"A": [0, 10, 30], "B": [0, -10, -30]}
... )
>>> b = tp.event_set(timestamps=[1, 4],
... features={"A": [10, 40], "B": [-10, -40]}
... )
>>> # Inputs a and b have some duplicated timestamps
>>> c = tp.combine(a, b)
>>> c
indexes: []
features: [('A', int64), ('B', int64)]
events:
(5 events):
timestamps: [0. 1. 1. 3. 4.]
'A': [ 0 10 10 30 40]
'B': [ 0 -10 -10 -30 -40]
...
>>> # Events with duplicated timestamps can be unified afterwards
>>> unique_t = c.unique_timestamps()
>>> d = c.moving_sum(window_length=tp.duration.shortest, sampling=unique_t)
>>> d
indexes: []
features: [('A', int64), ('B', int64)]
events:
(4 events):
timestamps: [0. 1. 3. 4.]
'A': [ 0 20 30 40]
'B': [ 0 -20 -30 -40]
...
```
Example with different index values
```python
# Index "idx=a" is only in a, "idx=b" in both, "idx=c" only in b
>>> a = tp.event_set(timestamps=[0, 1, 3],
... features={"A": [0, 10, 30],
... "idx": ["a", "a", "b"]},
... indexes=["idx"],
... )
>>> b = tp.event_set(timestamps=[1.5, 4.5, 5.5],
... features={"A": [15, 45, 55],
... "idx": ["b", "c", "c"]},
... indexes=["idx"]
... )
>>> # By default, "outer" uses index values from all inputs
>>> c = tp.combine(a, b)
>>> c
indexes: [('idx', str_)]
features: [('A', int64)]
events:
idx=b'a' (2 events):
timestamps: [0. 1.]
'A': [ 0 10]
idx=b'b' (2 events):
timestamps: [1.5 3. ]
'A': [15 30]
idx=b'c' (2 events):
timestamps: [4.5 5.5]
'A': [45 55]
...
>>> # Use "left" to use only index values from the first input a
>>> c = tp.combine(a, b, how="left")
>>> c
indexes: [('idx', str_)]
features: [('A', int64)]
events:
idx=b'a' (2 events):
timestamps: [0. 1.]
'A': [ 0 10]
idx=b'b' (2 events):
timestamps: [1.5 3. ]
'A': [15 30]
...
>>> # Use "inner" to use only index values that are present in all inputs
>>> c = tp.combine(a, b, how="inner")
>>> c
indexes: [('idx', str_)]
features: [('A', int64)]
events:
idx=b'b' (2 events):
timestamps: [1.5 3. ]
'A': [15 30]
...
```
Returns:
Type | Description |
---|---|
EventSetOrNode
|
An EventSet with events from all inputs combined. |