{"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":1295,"sourceCode":"            (Map(l), Map(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, fields)) => struct_eq_missing(\n                struct_owned_value_iter(l.as_ref()),","sourceCodeStart":1277,"sourceCodeEnd":1313,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/crates/polars-core/src/datatypes/any_value.rs#L1277-L1313","documentation":"AnyValue::eq_missing refuses to compare two Enum values whose FrozenCategory mappings are distinct Arc allocations. Enum's physical representation is a u32 index into its fixed FrozenCategories; equality across different FrozenCategories would compare unrelated indices. The Hash impl hashes the raw index, so the library panics with unimplemented!() rather than returning a wrong result.","triggerScenarios":"Calling AnyValue::eq_missing (or eq / tot_eq) with two AnyValue::Enum variants whose FrozenRevMapping Arcs differ — e.g. Enum columns created from two different Enums declarations or built in separate processes/frames without a shared frozen mapping.","commonSituations":"Comparing Enum-typed columns that came from different sources or different Enum type definitions with the same logical names, joining Enum frames built from distinct DataType::Enum instantiations, or deserializing Enum data without a shared mapping.","solutions":["Ensure both Enum columns use the same DataType::Enum definition (same categories, same order) so they share the FrozenCategories mapping","Cast both columns to Str and compare the string values","Cast both to their physical u32 representation only if you have verified the mappings are identical","Rebuild one column with the other's Enum data type via cast to a common Enum type"],"exampleFix":"// before: two Enum columns built from separate Enum definitions\nlet e1 = Series::new(\"e1\", [\"a\"]).unwrap().cast(&DataType::Enum(None, Arc::new(PlSmallStr::from_static(\"Enum1\")) /* distinct FrozenCategories */)).unwrap();\nlet e2 = Series::new(\"e2\", [\"a\"]).unwrap().cast(&DataType::Enum(None, Arc::new(PlSmallStr::from_static(\"Enum2\")))).unwrap();\nlet _ = e1.equal(&e2)?; // panics: different FrozenCategories\n// after: use one shared Enum data type\nlet dt = DataType::Enum(None, Arc::new(PlSmallStr::from_static(\"MyEnum\")));\nlet e1 = Series::new(\"e1\", [\"a\"]).unwrap().cast(&dt).unwrap();\nlet e2 = Series::new(\"e2\", [\"a\"]).unwrap().cast(&dt).unwrap();\nlet _ = e1.equal(&e2)?;","handlingStrategy":"validation","validationCode":"fn same_frozen_categories(a: &AnyValue, b: &AnyValue) -> bool {\n    match (a, b) {\n        (AnyValue::Enum(_, l), AnyValue::Enum(_, r)) => Arc::ptr_eq(l, r),\n        _ => false,\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Reuse one DataType::Enum definition for all columns of that enum","Cast to Str when comparing enums from unknown sources","Avoid rebuilding Enum dtypes after IO round-trips; cast to the existing dtype instead","Validate dtype equality of both sides before any comparison"],"tags":["polars","enum","comparison","unsupported-operation"],"backgroundTag":"unsupported-operation","analyzedSha":"fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e","analyzedAt":"2026-09-18T22:14:11.667Z","contentChangedAt":"2026-09-18T22:14:11.667Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}