{"record":{"id":"d23be6609da572ab","repo":"pola-rs/polars","slug":"scalar-ordering-for-mixed-dtypes-self-and-oth","errorCode":null,"errorMessage":"scalar ordering for mixed dtypes {self:?} and {other:?} is not supported","messagePattern":"scalar ordering for mixed dtypes (.+?) and (.+?) is not supported","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/polars-core/src/datatypes/any_value.rs","lineNumber":1462,"sourceCode":"            (Array(..), Array(..)) => {\n                unimplemented!(\"ordering for Array dtype is not supported\")\n            },\n            #[cfg(feature = \"object\")]\n            (Object(_), Object(_)) => {\n                unimplemented!(\"ordering for Object dtype is not supported\")\n            },\n            #[cfg(feature = \"dtype-struct\")]\n            (StructOwned(_), StructOwned(_))\n            | (StructOwned(_), Struct(..))\n            | (Struct(..), StructOwned(_))\n            | (Struct(..), Struct(..)) => {\n                unimplemented!(\"ordering for Struct dtype is not supported\")\n            },\n            #[cfg(feature = \"dtype-decimal\")]\n            (Decimal(lv, _lp, ls), Decimal(rv, _rp, rs)) => Some(dec128_cmp(*lv, *ls, *rv, *rs)),\n\n            (_, _) => {\n                unimplemented!(\n                    \"scalar ordering for mixed dtypes {self:?} and {other:?} is not supported\"\n                )\n            },\n        }\n    }\n}\n\nimpl TotalEq for AnyValue<'_> {\n    #[inline]\n    fn tot_eq(&self, other: &Self) -> bool {\n        self.eq_missing(other, true)\n    }\n}\n\n#[cfg(feature = \"dtype-struct\")]\nfn struct_to_avs_static(idx: usize, arr: &StructArray, fields: &[Field]) -> Vec<AnyValue<'static>> {\n    assert!(idx < arr.len());\n","sourceCodeStart":1444,"sourceCodeEnd":1480,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/crates/polars-core/src/datatypes/any_value.rs#L1444-L1480","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","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"],"exampleFix":"# before\nless = df[\"int_col\"].get(0) < df[\"float_col\"].get(0)  # Int64 vs Float64 -> panic\n\n# after\nless = float(df[\"int_col\"].get(0)) < float(df[\"float_col\"].get(0))","handlingStrategy":"validation","validationCode":"def scalars_comparable(a: pl.Series, b: pl.Series) -> bool:\n    return a.dtype == b.dtype or (a.dtype.is_numeric() and b.dtype.is_numeric())","typeGuard":"def orderable_pair(dt1, dt2) -> bool:\n    if dt1 != dt2:\n        return False\n    return not isinstance(dt1, (pl.List, pl.Array, pl.Struct)) and dt1 != pl.Object","tryCatchPattern":null,"preventionTips":["Cast columns to a common dtype before extracting and comparing scalars","Convert polars scalars to plain Python values when comparing across dtypes"],"tags":["rust","polars","panic","unimplemented","any-value","mixed-dtypes","ordering"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}