Skip to content

Serialize the logical plan of this LazyFrame to a file or string in JSON format

Source code

Description

Note that not all LazyFrames can be serialized. For example, LazyFrames that contain UDFs such as $map_elements() cannot be serialized.

Usage

<LazyFrame>$serialize()

Value

A character of the JSON representation of the logical plan

See Also

  • pl$deserialize_lf()

Examples

library("polars")

lf = pl$LazyFrame(a = 1:3)$sum()
json = lf$serialize()
json
#> [1] "{\"MapFunction\":{\"input\":{\"DataFrameScan\":{\"df\":{\"columns\":[{\"name\":\"a\",\"datatype\":\"Int32\",\"bit_settings\":\"\",\"values\":[1,2,3]}]},\"schema\":{\"fields\":{\"a\":\"Int32\"}}}},\"function\":{\"Stats\":\"Sum\"}}}"
# The logical plan can later be deserialized back into a LazyFrame.
pl$deserialize_lf(json)$collect()
#> shape: (1, 1)
#> ┌─────┐
#> │ a   │
#> │ --- │
#> │ i32 │
#> ╞═════╡
#> │ 6   │
#> └─────┘