temporian.EventSet.cast #
cast(
target: TargetDtypes, check_overflow: bool = True
) -> EventSetOrNode
Casts the data types of an EventSet
's features.
Features not impacted by cast are kept.
Usage example
>>> a = tp.event_set(
... timestamps=[1, 2],
... features={"A": [0, 2], "B": ['a', 'b'], "C": [5.0, 5.5]},
... )
>>> # Cast all input features to the same dtype
>>> b = a[["A", "C"]].cast(tp.float32)
>>> b
indexes: []
features: [('A', float32), ('C', float32)]
events:
(2 events):
timestamps: [1. 2.]
'A': [0. 2.]
'C': [5. 5.5]
...
>>> # Cast by feature name
>>> b = a.cast({'A': bool, 'C': int})
>>> b
indexes: []
features: [('A', bool_), ('B', str_), ('C', int64)]
events:
(2 events):
timestamps: [1. 2.]
'A': [False True]
'B': [b'a' b'b']
'C': [5 5]
...
>>> # Map original_dtype -> target_dtype
>>> b = a.cast({float: int, int: float})
>>> b
indexes: []
features: [('A', float64), ('B', str_), ('C', int64)]
events:
(2 events):
timestamps: [1. 2.]
'A': [0. 2.]
'B': [b'a' b'b']
'C': [5 5]
...
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target |
TargetDtypes
|
Single dtype or a map. Providing a single dtype will cast all
columns to it. The mapping keys can be either feature names or the
original dtypes (and not both types mixed), and the values are the
target dtypes for them. All dtypes must be Temporian types (see
|
required |
check_overflow |
bool
|
Flag to check overflow when casting to a dtype with a
shorter range (e.g: |
True
|
Returns:
Type | Description |
---|---|
EventSetOrNode
|
New EventSet (or the same if no features actually changed dtype),
with the same feature names as the input one, but with the new
dtypes as specified in |
Raises:
Type | Description |
---|---|
ValueError
|
If |
ValueError
|
If trying to cast a non-numeric string to numeric dtype. |
ValueError
|
If |
ValueError
|
If |