{"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":1458,"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-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(..)) => {","sourceCodeStart":1440,"sourceCodeEnd":1476,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/crates/polars-core/src/datatypes/any_value.rs#L1440-L1476","documentation":"Polars' AnyValue::partial_cmp (scalar comparison used in sorting/comparison paths) deliberately refuses to define an ordering between two List-typed values. Rust's unimplemented!() panics when two List scalars are compared. The library has no defined sort order for nested lists, so it aborts instead of returning a wrong result.","triggerScenarios":"Calling sort, sort_by, or any comparison-based operation (e.g. max, min, unique with maintain_order, or df.sort on a List column) where individual scalar values of dtype List must be ordered via AnyValue::partial_cmp.","commonSituations":"Sorting a DataFrame by a column whose dtype is List(...); comparing list values inside a map/apply that relies on Ord; passing list-typed data to an API that internally uses partial_cmp on AnyValues.","solutions":["Re-sort by an inner element instead, e.g. pl.col('list_col').list.first() (or .list.sort() inside) as the sort key","Flatten or explode the list column before sorting","Cast the list to a string (or another orderable repr) if a deterministic order on the serialization is acceptable","If list ordering is genuinely needed, file/track the upstream issue; consider polars feature requests or compute ordering manually in Python"],"exampleFix":"// before\ndf.sort('tags')  # tags: List(Utf8) -> panics\n// after\ndf.sort(pl.col('tags').list.first())","handlingStrategy":"validation","validationCode":"# python\ndef is_list_dtype(expr_or_col, schema):\n    return schema[expr_or_col] == pl.List or isinstance(schema[expr_or_col], pl.List)\n# check before sorting: assert not isinstance(df.schema[col], pl.List)","typeGuard":"def orderable_dtype(dtype) -> bool:\n    return not isinstance(dtype, (pl.List, pl.Array, pl.Struct, pl.Object))","tryCatchPattern":null,"preventionTips":["Check df.schema before sorting on nested columns","Sort by a scalar projection (list.first/arr.get/struct.field) instead of the nested column","Watch polars release notes for nested-type ordering support"],"tags":["polars","rust","sorting","nested-types"],"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"}