polars/polars-when-without-otherwise
| Pack | Severity | Fix | Versions |
|---|---|---|---|
| Polars | info | unsafe, with xpd check --fix --unsafe-fixes |
All versions |
Polars returns null for unmatched rows when then has no otherwise. Supply otherwise if those rows need a value.
df.select(pl.when(expr > 1).then(expr))df.select(pl.when(expr > 1).then(expr).otherwise(0))What the rule reports
Section titled “What the rule reports”The unhandled row held None. The explicit branch returned 0.
How to fix it
Section titled “How to fix it”With --unsafe-fixes, xpd adds .otherwise(None) to make the existing null result explicit. Supply a different value if unmatched rows need one.
Diagnostic message
Section titled “Diagnostic message”Polars returns null for unmatched rows when then has no otherwise. Supply otherwise if those rows need a value.See all rules in the Polars pack.