Skip to content

polars/polars-map-without-return-dtype

Pack Severity Fix Versions
Polars info none, edit by hand All versions

Polars may fail to infer the result type of a Python function. Pass return_dtype to declare the output type before collecting.

expr.map_elements(lambda value: (value,))
expr.map_elements(lambda value: (value,), return_dtype=pl.List(pl.Int64))

Inference produced List(Int64) on integer data and raised InvalidOperationError on two Null rows.

Edit the code using the replacement in the example.

Polars may fail to infer the result type of a Python function. Pass return_dtype to declare the output type before collecting.

See all rules in the Polars pack.