proxystore.serialize¶
Serialization functions.
serialize
¶
Serialize object.
Objects are serialized with different mechanisms depending on their type.
- bytes types are not serialized.
- str types are encoded to bytes.
- numpy.ndarray types are serialized using numpy.save.
- pandas.DataFrame types are serialized using to_pickle.
- polars.DataFrame types are serialized using write_ipc.
- Other types are pickled. If pickle fails, cloudpickle is used as a fallback.
Parameters:
-
obj
(Any
) –Object to serialize.
Returns:
-
bytes
–Bytes that can be passed to
deserialize()
.
Raises:
-
SerializationError
–If serializing the object fails with all available serializers. Cloudpickle is the last resort, so this error will typically be raised from a cloudpickle error.
Source code in proxystore/serialize.py
deserialize
¶
Deserialize object.
Warning
Pickled data is not secure, and malicious pickled object can execute arbitrary code when upickled. Only unpickle data you trust.
Parameters:
-
data
(bytes
) –Bytes produced by
serialize()
.
Returns:
-
Any
–The deserialized object.
Raises:
-
ValueError
–If
data
is not of typebytes
. -
SerializationError
–If the identifier of
data
is missing or invalid. The identifier is prepended to the string inserialize()
to indicate which serialization method was used (e.g., no serialization, pickle, etc.). -
SerializationError
–If pickle or cloudpickle raise an exception when deserializing the object.