Skip to content

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))

The unhandled row held None. The explicit branch returned 0.

With --unsafe-fixes, xpd adds .otherwise(None) to make the existing null result explicit. Supply a different value if unmatched rows need one.

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.