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 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.
Source
Thrown at crates/polars-core/src/datatypes/any_value.rs:1449
l_str.partial_cmp(r_str)
},
#[cfg(feature = "dtype-categorical")]
(Enum(l_cat, l_map), Enum(r_cat, r_map)) => {
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-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 df599052da)
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
Example fix
# before
out = sorted(df["obj"].to_list()) # comparing objects -> panic
# after
out = df.sort("obj_sort_key")["obj"].to_list() # order by a native key column Defensive patterns
Strategy: type-guard
Validate before calling
def orderable_dtype(dt) -> bool:
return not isinstance(dt, (pl.List, pl.Array, pl.Struct)) and dt != pl.Object Type guard
def orderable_dtype(dt) -> bool:
return not isinstance(dt, (pl.List, pl.Array, pl.Struct)) and dt != pl.Object Prevention
- Keep a native-dtype sort key column next to every Object column
- Convert Object columns to native dtypes before sorting or ranking
When it happens
Trigger: Comparing, sorting, or ranking scalars from an Object column (registered custom Rust type): df["obj"].get(0) < df["obj"].get(1).
Common situations: Custom Rust types stored in Object columns (e.g. geometries, decimals wrappers, intervals) that later flow into generic sort/min/max code paths.
Related errors
- comparing datetimes with different units or timezones is not
- comparing durations with different units is not supported
- can't order enums from different FrozenCategories
- ordering for List dtype is not supported
- ordering for Array dtype is not supported
AI-assisted analysis of pola-rs/polars@df599052da (2026-08-16).
Data as JSON: /api/errors/ef78b4ff90991930.
Report an issue: GitHub.