Skip to content

polars/polars-categorical-vs-enum

Rule polars-categorical-vs-enum
Pack Polars
Severity info
Fix none, edit by hand
Library versions every version

Categorical accepts every string label. Use Enum when you have a fixed list and want unknown labels to raise.

pl.Series(["open", "closed"], dtype=pl.Categorical)
pl.Series(["open", "closed"], dtype=pl.Enum(["open", "closed"]))

Categorical accepted typo. Enum raised InvalidOperationError for 1 unknown value.

Edit the code using the replacement in the example.

xpd prints this message with the issue. A name that starts with $ stands for code from your file.

Categorical accepts every string label. Use Enum when you have a fixed list and want unknown labels to raise.

Browse the other rules of the Polars pack.