pola-rs/polars · error
ordering for Object dtype is not supported
Error message
ordering for Object dtype is not supported
What it means
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.
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
Example fix
// before
df.sort('obj') # Object column -> panics
// after
df.sort(pl.col('obj').map_elements(lambda o: o.key, return_dtype=pl.Int64)) Defensive patterns
Strategy: validation
Validate before calling
if isinstance(df.schema[col], pl.Object):
raise ValueError('cannot order Object column; sort by a proxy primitive column') Type guard
def is_object_dtype(dtype) -> bool:
return dtype == pl.Object Prevention
- 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
When it happens
Trigger: Sorting or comparing a column of dtype Object(...) — e.g. df.sort('obj_col') or min/max over an Object column holding arbitrary objects.
Common situations: Columns created via pl.Series of Python objects or custom classes; users then attempting sort/unique-with-order/compare operations on them.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- creating extension types not allowed - try setting the…
- multiple nested objects not yet supported
- ordering for Array dtype is not supported
- ordering for List dtype is not supported
- ordering for Map dtype is not supported
AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18).
Data as JSON: /api/errors/ef78b4ff90991930.
Report an issue: GitHub.
Appendix: source
Thrown at crates/polars-core/src/datatypes/any_value.rs:1470
if !Arc::ptr_eq(l_map, r_map) {
unimplemented!("can't order enums from different FrozenCategories")
}
l_cat.partial_cmp(r_cat)
},
(List(_), List(_)) => {
unimplemented!("ordering for List dtype is not supported")
},
#[cfg(feature = "dtype-map")]
(Map(_), Map(_)) => {
unimplemented!("ordering for Map dtype is not supported")
},
#[cfg(feature = "dtype-array")]
(Array(..), Array(..)) => {
unimplemented!("ordering for Array dtype is not supported")
},
#[cfg(feature = "object")]
(Object(_), Object(_)) => {
unimplemented!("ordering for Object dtype is not supported")
},
#[cfg(feature = "dtype-struct")]
(StructOwned(_), StructOwned(_))
| (StructOwned(_), Struct(..))
| (Struct(..), StructOwned(_))
| (Struct(..), Struct(..)) => {
unimplemented!("ordering for Struct dtype is not supported")
},
#[cfg(feature = "dtype-decimal")]
(Decimal(lv, _lp, ls), Decimal(rv, _rp, rs)) => Some(dec128_cmp(*lv, *ls, *rv, *rs)),
(_, _) => {
unimplemented!(
"scalar ordering for mixed dtypes {self:?} and {other:?} is not supported"
)
},
}
}View on GitHub (pinned to fe841f959e)