deserialize#

pymc_extras.deserialize.deserialize(data: Any) Any[source]#

Deserialize a dictionary into a Python object.

Use the register_deserialization() function to add custom deserializations.

Deserialization is a two step process due to the dynamic nature of the data:

  1. Determine if the data is of the correct type.

  2. Deserialize the data into a Python object.

Each registered deserialization is checked in order until one is found that can deserialize the data. If no deserialization is found, a DeserializableError is raised.

A DeserializableError is raised when the data fails to be deserialized by any of the registered deserializers.

Parameters:

data (Any) – The data to deserialize.

Returns:

The deserialized object.

Return type:

Any

Raises:

DeserializableError – Raised when the data doesn’t match any registered deserializations or fails to be deserialized.

Examples

Deserialize a pymc_extras.prior.Prior object:

from pymc_extras.deserialize import deserialize

data = {"dist": "Normal", "kwargs": {"mu": 0, "sigma": 1}}
prior = deserialize(data)
# Prior("Normal", mu=0, sigma=1)