{"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":1470,"sourceCode":"                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)),\n\n            (_, _) => {\n                unimplemented!(\n                    \"scalar ordering for mixed dtypes {self:?} and {other:?} is not supported\"\n                )\n            },\n        }\n    }","sourceCodeStart":1452,"sourceCodeEnd":1488,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/crates/polars-core/src/datatypes/any_value.rs#L1452-L1488","documentation":"AnyValue::partial_cmp refuses to order Object-typed scalars (feature 'object') and panics with unimplemented!(). Arbitrary Python/Rust objects have no defined comparison, so Polars aborts rather than guessing.","triggerScenarios":"Sorting or comparing a column of dtype Object(...) — e.g. df.sort('obj_col') or min/max over an Object column holding arbitrary objects.","commonSituations":"Columns created via pl.Series of Python objects or custom classes; users then attempting sort/unique-with-order/compare operations on them.","solutions":["Store a comparable proxy column (e.g. the attribute to sort by) and sort by that","Convert objects to a primitive dtype (string/int) if possible","Sort indices separately in Python: df[df['o'].map(lambda v: v.key).argsort()]","Implement ordering on the object type only if Polars gains support"],"exampleFix":"// before\ndf.sort('obj')  # Object column -> panics\n// after\ndf.sort(pl.col('obj').map_elements(lambda o: o.key, return_dtype=pl.Int64))","handlingStrategy":"validation","validationCode":"if isinstance(df.schema[col], pl.Object):\n    raise ValueError('cannot order Object column; sort by a proxy primitive column')","typeGuard":"def is_object_dtype(dtype) -> bool:\n    return dtype == pl.Object","tryCatchPattern":null,"preventionTips":["Keep Object columns out of sort/compare paths","Maintain a parallel primitive key column for object rows","Prefer native dtypes over Python objects in Series"],"tags":["polars","rust","sorting","object-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"}