ToFloatConverter

utils.converters.ToFloatConverter(back_conversion: Callable | None = None)

Conversion from numpy array of various data formats to float and back

Methods

Name Description
from_timestamp_with_offset Convert timestamp back to datetime with offset.
to_float Convert numpy array to float, handling various data types.
to_orig Convert back to original data type from float.

from_timestamp_with_offset

utils.converters.ToFloatConverter.from_timestamp_with_offset(
    ts: datetime.timestamp,
    offset: float,
)

Convert timestamp back to datetime with offset.

Parameters

Name Type Description Default
ts float Timestamp value (seconds since epoch, with offset removed). required
offset float Offset timestamp to add back (seconds since epoch). required

Returns

Name Type Description
datetime Datetime object reconstructed from timestamp and offset.

to_float

utils.converters.ToFloatConverter.to_float(x: np.ndarray)

Convert numpy array to float, handling various data types.

Parameters

Name Type Description Default
x np.ndarray Input array with elements of the same type (datetime, float, or int). required

Returns

Name Type Description
np.ndarray Array converted to float. For datetime objects, converts to timestamps offset from the first value.

Raises

Name Type Description
AssertionError If input array contains mixed types.

to_orig

utils.converters.ToFloatConverter.to_orig(x: np.ndarray)

Convert back to original data type from float.

Converts to the type of the last input of self.to_float.

Parameters

Name Type Description Default
x np.ndarray Float array to convert back to original type. required

Returns

Name Type Description
np.ndarray Array converted to original data type.