{"record":{"id":"c9d4e292acb17571","repo":"pola-rs/polars","slug":"ordering-for-struct-dtype-is-not-supported","errorCode":null,"errorMessage":"ordering for Struct dtype is not supported","messagePattern":"ordering for Struct dtype is not supported","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/polars-core/src/datatypes/any_value.rs","lineNumber":1477,"sourceCode":"            },\n            #[cfg(feature = \"dtype-map\")]\n            (Map(_), Map(_)) => {\n                unimplemented!(\"ordering for Map dtype is not supported\")\n            },\n            #[cfg(feature = \"dtype-array\")]\n            (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    }","sourceCodeStart":1459,"sourceCodeEnd":1495,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/crates/polars-core/src/datatypes/any_value.rs#L1459-L1495","documentation":"AnyValue::partial_cmp does not implement ordering for Struct-typed scalars (feature 'dtype-struct') and panics via unimplemented!(). Polars cannot decide an ordering across struct values without a user-specified key column.","triggerScenarios":"Sorting by a Struct column, e.g. df.sort('s') where s: Struct, or any operation that needs scalar comparison of structs via partial_cmp.","commonSituations":"Nested data ingested from JSON/Arrow producing Struct columns, then attempting sort, min, max, or rank on the struct column directly.","solutions":["Sort by an inner field: pl.col('s').struct.field('name')","Use sort_by with a flattened key column","Explode/unpack the struct fields before ordering","Wait for/track upstream struct ordering support"],"exampleFix":"// before\ndf.sort('person')  # person: Struct{name,age} -> panics\n// after\ndf.sort(pl.col('person').struct.field('age'))","handlingStrategy":"validation","validationCode":"if isinstance(df.schema[col], pl.Struct):\n    key = pl.col(col).struct.field('name')  # pick an inner field","typeGuard":"def is_struct_dtype(dtype) -> bool:\n    return isinstance(dtype, pl.Struct)","tryCatchPattern":null,"preventionTips":["Always sort structs by an explicit inner field","Flatten struct columns early in the pipeline if ordering is needed","Check schemas after JSON/Arrow ingestion"],"tags":["polars","rust","sorting","struct-dtype"],"backgroundTag":"unsupported-operation","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"}