pola-rs/polars · error
scalar ordering for mixed dtypes {self:?} and {other:?} is n
Error message
scalar ordering for mixed dtypes {self:?} and {other:?} is not supported What it means
The catch-all arm of AnyValue::partial_cmp: ordering scalars of two different dtypes (e.g. Int64 vs Float64, String vs Int) is rejected. Scalar ordering requires like types; no supertype promotion is performed in this path.
Source
Thrown at crates/polars-core/src/datatypes/any_value.rs:1462
(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"
)
},
}
}
}
impl TotalEq for AnyValue<'_> {
#[inline]
fn tot_eq(&self, other: &Self) -> bool {
self.eq_missing(other, true)
}
}
#[cfg(feature = "dtype-struct")]
fn struct_to_avs_static(idx: usize, arr: &StructArray, fields: &[Field]) -> Vec<AnyValue<'static>> {
assert!(idx < arr.len());
View on GitHub (pinned to df599052da)
Solutions
- Cast both sides to a common dtype before extracting scalars: pl.concat([df["a"], df["b"]]).cast(common_dtype)
- In Python, convert to plain Python types (int/float/str) before comparing
- Align schemas at load/concat time (e.g. with_dicts/with_columns cast) so scalar dtypes match
Example fix
# before less = df["int_col"].get(0) < df["float_col"].get(0) # Int64 vs Float64 -> panic # after less = float(df["int_col"].get(0)) < float(df["float_col"].get(0))
Defensive patterns
Strategy: validation
Validate before calling
def scalars_comparable(a: pl.Series, b: pl.Series) -> bool:
return a.dtype == b.dtype or (a.dtype.is_numeric() and b.dtype.is_numeric()) Type guard
def orderable_pair(dt1, dt2) -> bool:
if dt1 != dt2:
return False
return not isinstance(dt1, (pl.List, pl.Array, pl.Struct)) and dt1 != pl.Object Prevention
- Cast columns to a common dtype before extracting and comparing scalars
- Convert polars scalars to plain Python values when comparing across dtypes
When it happens
Trigger: Comparing AnyValues whose dtypes differ: df["a"].get(0) < df["b"].get(1) where a is Int64 and b is Float64 or String; generic min/max over heterogeneous columns; sorting a mixed bag of scalars.
Common situations: Comparing a literal against a column value of a different type in Python, or aggregating scalars from columns that were never schema-aligned (int vs float, int vs string after a schema change).
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/d23be6609da572ab.
Report an issue: GitHub.