{"record":{"id":"aafbd2e7dbedbeb8","repo":"pola-rs/polars","slug":"ordering-for-map-dtype-is-not-supported","errorCode":null,"errorMessage":"ordering for Map dtype is not supported","messagePattern":"ordering for Map dtype is not supported","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/polars-core/src/datatypes/any_value.rs","lineNumber":1462,"sourceCode":"            #[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-map\")]\n            (Map(_), Map(_)) => {\n                unimplemented!(\"ordering for Map 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(_))\n            | (Struct(..), Struct(..)) => {\n                unimplemented!(\"ordering for Struct dtype is not supported\")\n            },\n            #[cfg(feature = \"dtype-decimal\")]\n            (Decimal(lv, _lp, ls), Decimal(rv, _rp, rs)) => Some(dec128_cmp(*lv, *ls, *rv, *rs)),","sourceCodeStart":1444,"sourceCodeEnd":1480,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/crates/polars-core/src/datatypes/any_value.rs#L1444-L1480","documentation":"AnyValue::partial_cmp does not define an ordering for Map-typed scalar values and panics via unimplemented!(). Polars treats maps as unordered key-value collections, so comparing two Map values for sort/comparison purposes is intentionally unsupported.","triggerScenarios":"Sorting or comparing a column of dtype Map, e.g. df.sort on a map column, or any operation that invokes AnyValue::partial_cmp on Map scalars (feature 'dtype-map' enabled).","commonSituations":"Users with map data (often from other engines) trying to sort a DataFrame by a map column; using min/max on a map column.","solutions":["Sort by a specific key: pl.col('m').struct.field('key') or extract the relevant value first","Convert the map to a struct or list and order by one of its fields","Drop the map column from the sort keys","Compute ordering in Python via map_elements if performance allows"],"exampleFix":"// before\ndf.sort('props')  # props: Map -> panics\n// after\ndf.sort(pl.col('props').struct.field('score'))","handlingStrategy":"validation","validationCode":"if isinstance(df.schema[col], (pl.Struct,)) or str(df.schema[col]).startswith('Map'):\n    raise ValueError(f'{col} is not scalar-orderable; pick a key to sort by')","typeGuard":"def is_map_dtype(dtype) -> bool:\n    return 'Map' in str(dtype)","tryCatchPattern":null,"preventionTips":["Treat Map columns as unordered; always sort by extracted keys","Convert maps to structs when order matters","Verify schema after cross-engine data ingestion"],"tags":["polars","rust","sorting","map-dtype"],"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"}