pola-rs/polars · error
ordering for List dtype is not supported
Error message
ordering for List dtype is not supported
What it means
AnyValue::partial_cmp has no ordering implementation for List values - nested list scalars are explicitly rejected with unimplemented!(). There is no total, cheap, and universally agreed ordering over variable-length lists at the scalar level.
Source
Thrown at crates/polars-core/src/datatypes/any_value.rs:1441
lt.partial_cmp(rt)
},
#[cfg(feature = "dtype-time")]
(Time(l), Time(r)) => l.partial_cmp(r),
#[cfg(feature = "dtype-categorical")]
(Categorical(l_cat, l_map), Categorical(r_cat, r_map)) => unsafe {
let l_str = l_map.cat_to_str_unchecked(*l_cat);
let r_str = r_map.cat_to_str_unchecked(*r_cat);
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)),View on GitHub (pinned to df599052da)
Solutions
- Do comparisons at the expression/Series level: list.eval / list.get(i) to extract a comparable element, or compute a sort key (list.len(), list.sum(), first element)
- Compare element-wise after exploding: df.explode("lst") then order the inner column
- Serialize to a comparable representation (e.g. sort the list and hash, or cast to String) when a total order is genuinely needed
Example fix
# before
first_is_smaller = df["lst"].get(0) < df["lst"].get(1) # panics
# after
first_is_smaller = (
df["lst"].list.first().get(0) < df["lst"].list.first().get(1)
) 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
- Never compare list scalars with < >; derive a scalar key (list.first, list.len, list.sum) instead
- Push ordering into expressions: sort by computed list keys rather than list cells
When it happens
Trigger: Any direct ordering comparison of two List AnyValues: df["lst"].get(0) < df["lst"].get(1), sorted() over list scalars, or generic scalar min/max utilities applied to a List column.
Common situations: User code that pulls individual cell values out of a list column and compares them, or frameworks that sort heterogeneous scalars including lists.
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 Array dtype is not supported
- ordering for Object dtype is not supported
AI-assisted analysis of pola-rs/polars@df599052da (2026-08-16).
Data as JSON: /api/errors/6708852262740436.
Report an issue: GitHub.