{"record":{"id":"ef78b4ff90991930","repo":"pola-rs/polars","slug":"ordering-for-object-dtype-is-not-supported","errorCode":null,"errorMessage":"ordering for Object dtype is not supported","messagePattern":"ordering for Object dtype is not supported","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/polars-core/src/datatypes/any_value.rs","lineNumber":1449,"sourceCode":"                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(_))\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)),\n\n            (_, _) => {\n                unimplemented!(\n                    \"scalar ordering for mixed dtypes {self:?} and {other:?} is not supported\"\n                )\n            },\n        }\n    }","sourceCodeStart":1431,"sourceCodeEnd":1467,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/crates/polars-core/src/datatypes/any_value.rs#L1431-L1467","documentation":"AnyValue::partial_cmp cannot order Object scalars. Object values are opaque user-defined types registered via the PolarsObject mechanism; polars has no ordering rule for them unless the user supplies one, so the arm is unimplemented.","triggerScenarios":"Comparing, sorting, or ranking scalars from an Object column (registered custom Rust type): df[\"obj\"].get(0) < df[\"obj\"].get(1).","commonSituations":"Custom Rust types stored in Object columns (e.g. geometries, decimals wrappers, intervals) that later flow into generic sort/min/max code paths.","solutions":["Store a comparable key alongside the object (a separate Int/Float/String column) and sort by that","Convert the object column to a native dtype before ordering","In Rust, order by downcasting the objects yourself in user code rather than via AnyValue comparisons"],"exampleFix":"# before\nout = sorted(df[\"obj\"].to_list())  # comparing objects -> panic\n\n# after\nout = df.sort(\"obj_sort_key\")[\"obj\"].to_list()  # order by a native key column","handlingStrategy":"type-guard","validationCode":"def orderable_dtype(dt) -> bool:\n    return not isinstance(dt, (pl.List, pl.Array, pl.Struct)) and dt != pl.Object","typeGuard":"def orderable_dtype(dt) -> bool:\n    return not isinstance(dt, (pl.List, pl.Array, pl.Struct)) and dt != pl.Object","tryCatchPattern":null,"preventionTips":["Keep a native-dtype sort key column next to every Object column","Convert Object columns to native dtypes before sorting or ranking"],"tags":["rust","polars","panic","unimplemented","any-value","object","ordering"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}