polars/polars-when-without-otherwise
| Rule | polars-when-without-otherwise |
|---|---|
| Pack | Polars |
| Severity | info |
| Fix | unsafe, with xpd check --fix --unsafe-fixes |
| Library versions | every version |
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.
Message
Section titled “Message”xpd prints this message with the issue. A name that starts with $ stands for code from your file.
Polars returns null for unmatched rows when then has no otherwise. Supply otherwise if those rows need a value.Browse the other rules of the Polars pack.