Some Polars operations, such as .sort() fail when passed a column with a Nested Type.
This (sensible) choice about sort means I cannot use my usual sorting pattern of df.sort(pl.all()).
import polars as pl
NESTED_TYPES = [
pl.List,
pl.Array,
pl.Object,
pl.Struct
]
pl.exclude(NESTED_TYPES)
Result:
*.exclude([Dtype(List(Null)), Dtype(Array(Null, 0)), Dtype(Object("object", None)), Dtype(Struct([]))])
Is there a way to select (or exclude) only nested types?
The Selectors Documentation has many ideas but nothing seems right for this.
It is not very well supported yet, see https://github.com/pola-rs/polars/issues/9971
As a workaround, you can specify "all types except non-nested types" using the code shown in that Issue, or just loop over all dtypes you care about and specify pl.List(dtype) for each of them, but there aren't any good ways to say "all list dtypes" yet.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With