{"record":{"id":"d23be6609da572ab","repo":"pola-rs/polars","slug":"scalar-ordering-for-mixed-dtypes-self-and-other-is-not","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":1483,"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":1465,"sourceCodeEnd":1501,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/crates/polars-core/src/datatypes/any_value.rs#L1465-L1501","documentation":"AnyValue::partial_cmp reached its catch-all arm: two scalars of different or unorderable dtypes were compared, and no comparison rule exists. This is a dtype-mismatch at the scalar comparison level — Polars refuses to impose an arbitrary order.","triggerScenarios":"Comparing AnyValues of different dtypes (e.g. Int64 vs Utf8, Decimal vs Float) through APIs built on partial_cmp, or through feature-unusual pairings (e.g. Binary vs Int, Time vs Datetime) in sort/comparison contexts.","commonSituations":"Mixed-type columns produced by concat, melt/pivot, or CSV parsing with inconsistent types; sort_keys of differing dtypes; after schema changes the compared columns no longer match.","solutions":["Cast both sides to a common dtype before comparing: pl.col('a').cast(pl.Utf8) == pl.col('b')","Inspect dtypes first (df.schema) and fix parsing/ingestion so columns share one dtype","Use strict=False casts or explicit fill for nulls where types differ","For sorts, ensure all sort keys share the same dtype"],"exampleFix":"// before\ndf.filter(pl.col('a') == pl.col('b'))  # a: Int64, b: Utf8 -> panics\n// after\ndf.filter(pl.col('a').cast(pl.Utf8) == pl.col('b'))","handlingStrategy":"validation","validationCode":"schema = df.collect_schema()\nassert schema['a'].base_type() == schema['b'].base_type(), f\"dtype mismatch: {schema['a']} vs {schema['b']}\"","typeGuard":"def same_dtype(a: pl.DataType, b: pl.DataType) -> bool:\n    return a == b","tryCatchPattern":"try:\n    out = df.filter(pl.col('a') == pl.col('b'))\nexcept Exception as e:\n    if 'scalar ordering' in str(e):\n        out = df.filter(pl.col('a').cast(pl.Utf8, strict=False) == pl.col('b'))\n    else:\n        raise","preventionTips":["Compare dtypes of both sides before comparisons/sorts","Normalize schemas after concat/melt/pivot/CSV reads with explicit casts","Use .cast(..., strict=False) deliberately and validate results"],"tags":["polars","rust","dtype-mismatch","comparison"],"backgroundTag":"dtype-mismatch","analyzedSha":"fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e","analyzedAt":"2026-09-18T22:14:11.667Z","contentChangedAt":"2026-09-18T22:14:11.667Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}