{"record":{"id":"60417628434af9fa","repo":"pola-rs/polars","slug":"can-t-order-enums-from-different-frozencategories","errorCode":null,"errorMessage":"can't order enums from different FrozenCategories","messagePattern":"can't order enums from different FrozenCategories","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/polars-core/src/datatypes/any_value.rs","lineNumber":1436,"sourceCode":"            (Duration(lt, lu), Duration(rt, ru)) => {\n                if lu != ru {\n                    unimplemented!(\"comparing durations with different units is not supported\");\n                }\n\n                lt.partial_cmp(rt)\n            },\n            #[cfg(feature = \"dtype-time\")]\n            (Time(l), Time(r)) => l.partial_cmp(r),\n            #[cfg(feature = \"dtype-categorical\")]\n            (Categorical(l_cat, l_map), Categorical(r_cat, r_map)) => unsafe {\n                let l_str = l_map.cat_to_str_unchecked(*l_cat);\n                let r_str = r_map.cat_to_str_unchecked(*r_cat);\n                l_str.partial_cmp(r_str)\n            },\n            #[cfg(feature = \"dtype-categorical\")]\n            (Enum(l_cat, l_map), Enum(r_cat, r_map)) => {\n                if !Arc::ptr_eq(l_map, r_map) {\n                    unimplemented!(\"can't order enums from different FrozenCategories\")\n                }\n                l_cat.partial_cmp(r_cat)\n            },\n            (List(_), List(_)) => {\n                unimplemented!(\"ordering for List dtype is not supported\")\n            },\n            #[cfg(feature = \"dtype-array\")]\n            (Array(..), Array(..)) => {\n                unimplemented!(\"ordering for Array dtype is not supported\")\n            },\n            #[cfg(feature = \"object\")]\n            (Object(_), Object(_)) => {\n                unimplemented!(\"ordering for Object dtype is not supported\")\n            },\n            #[cfg(feature = \"dtype-struct\")]\n            (StructOwned(_), StructOwned(_))\n            | (StructOwned(_), Struct(..))\n            | (Struct(..), StructOwned(_))","sourceCodeStart":1418,"sourceCodeEnd":1454,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/crates/polars-core/src/datatypes/any_value.rs#L1418-L1454","documentation":"AnyValue::partial_cmp panics when ordering two Enum values backed by different FrozenCategories maps. Unlike Categorical (which falls back to comparing category strings), enum ordering is defined by category position within one frozen list, so a cross-map comparison has no meaning and is rejected.","triggerScenarios":"Sorting or comparing (<, >, min/max) Enum AnyValues from two separately constructed pl.Enum dtypes: sorted([a[\"e\"].get(0), b[\"e\"].get(0)]) where the two enum columns have independent category definitions.","commonSituations":"Merging or ranking values from frames whose enum columns were declared independently, or mixing enum literals from a different dtype instance.","solutions":["Cast to String before ordering when you want lexicographic order of the category names","Unify the enum dtype first (cast one column to the other's pl.Enum dtype) so both values share one frozen map and positional ordering applies","Avoid scalar-level ordering of enums; sort the Series after aligning dtypes"],"exampleFix":"# before\nm = min(a[\"e\"].get(0), b[\"e\"].get(0))  # different Enum maps -> panic\n\n# after\nm = min(str(a[\"e\"].cast(pl.String).get(0)), str(b[\"e\"].cast(pl.String).get(0)))","handlingStrategy":"validation","validationCode":"def enums_orderable(a: pl.Series, b: pl.Series) -> bool:\n    return a.dtype == b.dtype  # same Enum dtype -> same frozen categories","typeGuard":"def orderable_enum_scalars(a: pl.Series, b: pl.Series) -> bool:\n    return isinstance(a.dtype, pl.Enum) and a.dtype == b.dtype","tryCatchPattern":"try:\n    m = min(e1, e2)\nexcept Exception:\n    m = min(str(e1.cast(pl.String)), str(e2.cast(pl.String)))","preventionTips":["Reuse one plEnum dtype instance for logically identical enums","Sort enum values via the Series (dtype-aligned) path, not via raw scalars"],"tags":["rust","polars","panic","unimplemented","any-value","enum","ordering"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}