Skip to content

polars/polars-categorical-vs-enum

Pack Severity Fix Versions
Polars info none, edit by hand All versions

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.

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

See all rules in the Polars pack.