{"record":{"id":"f714a6eec6140a6b","repo":"pola-rs/polars","slug":"comparing-enums-with-different-frozencategories-is","errorCode":null,"errorMessage":"comparing enums with different FrozenCategories is not supported through AnyValue","messagePattern":"comparing enums with different FrozenCategories is not supported through AnyValue","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/polars-core/src/datatypes/any_value.rs","lineNumber":1278,"sourceCode":"            (List(l), List(r)) => l == r,\n            #[cfg(feature = \"dtype-categorical\")]\n            (Categorical(cat_l, map_l), Categorical(cat_r, map_r)) => {\n                if !Arc::ptr_eq(map_l, map_r) {\n                    // We can't support this because our Hash impl directly hashes the index. If you\n                    // add support for this we must change the Hash impl.\n                    unimplemented!(\n                        \"comparing categoricals with different Categories is not supported through AnyValue\"\n                    );\n                }\n\n                cat_l == cat_r\n            },\n            #[cfg(feature = \"dtype-categorical\")]\n            (Enum(cat_l, map_l), Enum(cat_r, map_r)) => {\n                if !Arc::ptr_eq(map_l, map_r) {\n                    // We can't support this because our Hash impl directly hashes the index. If you\n                    // add support for this we must change the Hash impl.\n                    unimplemented!(\n                        \"comparing enums with different FrozenCategories is not supported through AnyValue\"\n                    );\n                }\n\n                cat_l == cat_r\n            },\n            #[cfg(feature = \"dtype-duration\")]\n            (Duration(l, tu_l), Duration(r, tu_r)) => l == r && tu_l == tu_r,\n\n            #[cfg(feature = \"dtype-struct\")]\n            (StructOwned(l), StructOwned(r)) => struct_eq_missing(\n                struct_owned_value_iter(l.as_ref()),\n                struct_owned_value_iter(r.as_ref()),\n                null_equal,\n            ),\n            #[cfg(feature = \"dtype-struct\")]\n            (StructOwned(l), Struct(idx, arr, _)) => struct_eq_missing(\n                struct_owned_value_iter(l.as_ref()),","sourceCodeStart":1260,"sourceCodeEnd":1296,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/crates/polars-core/src/datatypes/any_value.rs#L1260-L1296","documentation":"PartialEq for AnyValue panics when comparing two Enum values whose FrozenCategories maps are different Arc allocations. Enum categories are fixed per dtype; two distinct map objects mean two different enum types, and the index-hashing Hash impl forbids cross-map equality, so the guard trips.","triggerScenarios":"Comparing Enum AnyValues from columns declared with separate pl.Enum([...]) definitions (even with identical category lists), e.g. df1[\"e\"].get(0) == df2[\"e\"].get(0) where the enums were constructed independently.","commonSituations":"Reused column definitions that each construct a new pl.Enum([...]), comparing enum scalars across DataFrames or against enum literals from a different dtype instance.","solutions":["Cast both enum columns to String and compare the string values","Unify the enum dtype: reuse one pl.Enum([...]) dtype object (or cast one column to the other's dtype) so both sides share the same frozen categories","Avoid scalar-level == on enums; compare at the Series level after aligning dtypes"],"exampleFix":"# before\nok = a[\"e\"].get(0) == b[\"e\"].get(0)  # two distinct Enum dtypes -> panic\n\n# after\nok = str(a[\"e\"].cast(pl.String).get(0)) == str(b[\"e\"].cast(pl.String).get(0))","handlingStrategy":"validation","validationCode":"def enum_scalars_comparable(a: pl.Series, b: pl.Series) -> bool:\n    return a.dtype == b.dtype  # identical Enum dtype -> same frozen categories","typeGuard":"def same_enum(a: pl.Series, b: pl.Series) -> bool:\n    return isinstance(a.dtype, pl.Enum) and isinstance(b.dtype, pl.Enum) and a.dtype == b.dtype","tryCatchPattern":"try:\n    eq = e1 == e2\nexcept Exception:\n    eq = str(e1.cast(pl.String)) == str(e2.cast(pl.String))","preventionTips":["Define each pl.Enum dtype once and reuse the object across frames","Compare enum values as strings when dtypes may differ","Cast both sides to one enum dtype before scalar comparisons"],"tags":["rust","polars","panic","unimplemented","any-value","enum","equality"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}