hyloa.utils.df_serial module

Code to create a robust cross-platform serialization for pandas DataFrames.

class hyloa.utils.df_serial.DataFrameSerializer[source]

Bases: object

Robust cross-platform serialization for pandas DataFrames.

This class handles serialization with explicit dtype preservation, ensuring compatibility across different: - Operating systems (Windows, Linux, macOS) - NumPy/Pandas versions

The serialization strategy: 1. Use native Python dtypes (int, float, str, bool) instead of NumPy dtypes 2. Store column-level dtype info in a standard format 3. Handle NaN/None values explicitly 4. Preserve index information

static deserialize(serialized: Dict[str, Any]) DataFrame[source]

Deserialize a portable dictionary format back into a Pandas DataFrame.

Parameters:

serialized (dict) – The serialized representation of the DataFrame.

Returns:

The reconstructed DataFrame.

Return type:

pd.DataFrame

static serialize(df: DataFrame) Dict[str, Any][source]

Serialize a Pandas DataFrame into a portable dictionary format.

Parameters:

df (pd.DataFrame) – The DataFrame to serialize.

Returns:

Portable representation with keys: ‘columns’, ‘index’, ‘data’, ‘dtypes’, ‘attrs’

Return type:

dict