pola-rs/polars · error

ordering for List dtype is not supported

Error message

ordering for List dtype is not supported

What it means

Polars' AnyValue::partial_cmp (scalar comparison used in sorting/comparison paths) deliberately refuses to define an ordering between two List-typed values. Rust's unimplemented!() panics when two List scalars are compared. The library has no defined sort order for nested lists, so it aborts instead of returning a wrong result.

Solutions

  1. Re-sort by an inner element instead, e.g. pl.col('list_col').list.first() (or .list.sort() inside) as the sort key
  2. Flatten or explode the list column before sorting
  3. Cast the list to a string (or another orderable repr) if a deterministic order on the serialization is acceptable
  4. If list ordering is genuinely needed, file/track the upstream issue; consider polars feature requests or compute ordering manually in Python

Example fix

// before
df.sort('tags')  # tags: List(Utf8) -> panics
// after
df.sort(pl.col('tags').list.first())
Defensive patterns

Strategy: validation

Validate before calling

# python
def is_list_dtype(expr_or_col, schema):
    return schema[expr_or_col] == pl.List or isinstance(schema[expr_or_col], pl.List)
# check before sorting: assert not isinstance(df.schema[col], pl.List)

Type guard

def orderable_dtype(dtype) -> bool:
    return not isinstance(dtype, (pl.List, pl.Array, pl.Struct, pl.Object))

Prevention

When it happens

Trigger: Calling sort, sort_by, or any comparison-based operation (e.g. max, min, unique with maintain_order, or df.sort on a List column) where individual scalar values of dtype List must be ordered via AnyValue::partial_cmp.

Common situations: Sorting a DataFrame by a column whose dtype is List(...); comparing list values inside a map/apply that relies on Ord; passing list-typed data to an API that internally uses partial_cmp on AnyValues.

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


AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18). Data as JSON: /api/errors/6708852262740436. Report an issue: GitHub.

Appendix: source

Thrown at crates/polars-core/src/datatypes/any_value.rs:1458

                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-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(..)) => {

View on GitHub (pinned to fe841f959e)