polars.Expr.deserialize#

classmethod Expr.deserialize(
source: str | Path | IOBase | bytes,
*,
format: SerializationFormat = 'binary',
) Expr[source]#

Read a serialized expression from a file.

Parameters:
source

Path to a file or a file-like object (by file-like object, we refer to objects that have a read() method, such as a file handler (e.g. via builtin open function) or BytesIO).

format

The format with which the Expr was serialized. Options:

  • "binary": Deserialize from binary format (bytes). This is the default.

  • "json": Deserialize from JSON format (string).

Warning

This function uses pickle if the logical plan contains Python UDFs, and as such inherits the security implications. Deserializing can execute arbitrary code, so it should only be attempted on trusted data.

Notes

Serialization is not stable across Polars versions: a LazyFrame serialized in one Polars version may not be deserializable in another Polars version.

Examples

>>> import io
>>> expr = pl.col("foo").sum().over("bar")
>>> bytes = expr.meta.serialize()
>>> pl.Expr.deserialize(io.BytesIO(bytes))  
<Expr ['col("foo").sum().over([col("ba…'] at ...>