{"record":{"id":"6708852262740436","repo":"pola-rs/polars","slug":"ordering-for-list-dtype-is-not-supported","errorCode":null,"errorMessage":"ordering for List dtype is not supported","messagePattern":"ordering for List dtype is not supported","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/polars-core/src/datatypes/any_value.rs","lineNumber":1441,"sourceCode":"                lt.partial_cmp(rt)\n            },\n            #[cfg(feature = \"dtype-time\")]\n            (Time(l), Time(r)) => l.partial_cmp(r),\n            #[cfg(feature = \"dtype-categorical\")]\n            (Categorical(l_cat, l_map), Categorical(r_cat, r_map)) => unsafe {\n                let l_str = l_map.cat_to_str_unchecked(*l_cat);\n                let r_str = r_map.cat_to_str_unchecked(*r_cat);\n                l_str.partial_cmp(r_str)\n            },\n            #[cfg(feature = \"dtype-categorical\")]\n            (Enum(l_cat, l_map), Enum(r_cat, r_map)) => {\n                if !Arc::ptr_eq(l_map, r_map) {\n                    unimplemented!(\"can't order enums from different FrozenCategories\")\n                }\n                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)),","sourceCodeStart":1423,"sourceCodeEnd":1459,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/crates/polars-core/src/datatypes/any_value.rs#L1423-L1459","documentation":"AnyValue::partial_cmp has no ordering implementation for List values - nested list scalars are explicitly rejected with unimplemented!(). There is no total, cheap, and universally agreed ordering over variable-length lists at the scalar level.","triggerScenarios":"Any direct ordering comparison of two List AnyValues: df[\"lst\"].get(0) < df[\"lst\"].get(1), sorted() over list scalars, or generic scalar min/max utilities applied to a List column.","commonSituations":"User code that pulls individual cell values out of a list column and compares them, or frameworks that sort heterogeneous scalars including lists.","solutions":["Do comparisons at the expression/Series level: list.eval / list.get(i) to extract a comparable element, or compute a sort key (list.len(), list.sum(), first element)","Compare element-wise after exploding: df.explode(\"lst\") then order the inner column","Serialize to a comparable representation (e.g. sort the list and hash, or cast to String) when a total order is genuinely needed"],"exampleFix":"# before\nfirst_is_smaller = df[\"lst\"].get(0) < df[\"lst\"].get(1)  # panics\n\n# after\nfirst_is_smaller = (\n    df[\"lst\"].list.first().get(0) < df[\"lst\"].list.first().get(1)\n)","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":["Never compare list scalars with < >; derive a scalar key (list.first, list.len, list.sum) instead","Push ordering into expressions: sort by computed list keys rather than list cells"],"tags":["rust","polars","panic","unimplemented","any-value","list","ordering"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}