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))What the rule reports
Section titled “What the rule reports”Inference produced List(Int64) on integer data and raised InvalidOperationError on two Null rows.
How to fix it
Section titled “How to fix it”Edit the code using the replacement in the example.
Diagnostic message
Section titled “Diagnostic message”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.