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"]))What the rule reports
Section titled “What the rule reports”Categorical accepted typo. Enum raised InvalidOperationError for 1 unknown value.
How to fix it
Section titled “How to fix it”Edit the code using the replacement in the example.
Diagnostic message
Section titled “Diagnostic message”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.