pola-rs/polars · error

ordering for Array dtype is not supported

Error message

ordering for Array dtype is not supported

What it means

AnyValue::partial_cmp rejects ordering between Array (fixed-size list) scalars. Like List, there is no scalar-level ordering kernel for nested array values, so the arm panics with unimplemented!().

Source

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

            #[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)),

            (_, _) => {
                unimplemented!(
                    "scalar ordering for mixed dtypes {self:?} and {other:?} is not supported"

View on GitHub (pinned to df599052da)

Solutions

  1. Extract an element or reduce to a scalar key first: arr.get(0), arr.sum(), or dot products via expressions, then compare
  2. Use Array-level expressions (polars supports element-wise ops on pl.Array) instead of scalar comparisons
  3. Cast the column to List and use list expressions if you need list-style ordering helpers

Example fix

# before
smaller = df["vec"].get(0) < df["vec"].get(1)  # panics

# after
smaller = df["vec"].arr.get(0).get(0) < df["vec"].arr.get(0).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

When it happens

Trigger: Comparing two Array AnyValues with <, >, min, max, or sorting scalars extracted from a pl.Array column: df["arr"].get(0) < df["arr"].get(1).

Common situations: Fixed-width embedding/vector columns where user code tries to rank or compare individual vectors cell by cell.

Related errors


AI-assisted analysis of pola-rs/polars@df599052da (2026-08-16). Data as JSON: /api/errors/8cec531b94f1bbb6. Report an issue: GitHub.