{"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":1456,"sourceCode":"                l_cat.partial_cmp(r_cat)\n            },\n            (List(_), List(_)) => {\n                unimplemented!(\"ordering for List 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":1438,"sourceCodeEnd":1474,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/crates/polars-core/src/datatypes/any_value.rs#L1438-L1474","documentation":"AnyValue::partial_cmp has no ordering for Struct scalars (all Struct/StructOwned combinations). Ordering nested structs field-by-field is not implemented at the scalar level, so any comparison attempt panics.","triggerScenarios":"Comparing struct cell values: df[\"s\"].get(0) < df[\"s\"].get(1), sorted() over values from a Struct column, or scalar min/max over struct fields.","commonSituations":"Rows carrying struct payloads (JSON-derived data, named tuples) where user code tries to rank cells or sort raw Python/polars struct scalars directly.","solutions":["Order by extracted struct fields: df.sort(pl.col(\"s\").struct.field(\"priority\"))","Flatten the struct (df.unnest(\"s\")) and sort by the resulting columns","Compute a comparison key from the struct fields and sort by that instead of comparing whole structs"],"exampleFix":"# before\nvals = sorted(df[\"s\"].to_list())  # struct scalars -> panic on comparison\n\n# after\nvals = df.sort(pl.col(\"s\").struct.field(\"priority\"))[\"s\"].to_list()","handlingStrategy":"type-guard","validationCode":"def orderable_dtype(dt) -> bool:\n    return not isinstance(dt, (pl.List, pl.Array, pl.Struct)) and dt != pl.Object","typeGuard":"def orderable_dtype(dt) -> bool:\n    return not isinstance(dt, (pl.List, pl.Array, pl.Struct)) and dt != pl.Object","tryCatchPattern":null,"preventionTips":["Sort by struct.field(...) keys or unnest before ordering","Compute a scalar sort key from struct fields instead of comparing whole structs"],"tags":["rust","polars","panic","unimplemented","any-value","struct","ordering"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}