Skip to content

Add pl.Expr.list.item() as a way to retrieve the single item in a list (or raise when there is none or more than one) #24660

@mkleinbort-wl

Description

@mkleinbort-wl

Description

It's a low-priority ask - I came across a problem where it would have been handy.

df_ans = df.with_columns(cs.list().list.item()) # all columns "should" be lists of length 1

It takes inspiration from pl.DataFrame.item() which returns the single value unless there is more than one, in which case it raises.

The alternatives are involved - either a cast to an array, an explode, a len() check, or sorting, grabbing the first & last, and asserting equality

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or an improvement of an existing feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions