Skip to content

Add Expr.list.agg for aggregating list contents #22650

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
orlp opened this issue May 7, 2025 · 0 comments
Open

Add Expr.list.agg for aggregating list contents #22650

orlp opened this issue May 7, 2025 · 0 comments
Labels
accepted Ready for implementation enhancement New feature or an improvement of an existing feature P-low Priority: low

Comments

@orlp
Copy link
Member

orlp commented May 7, 2025

This expression would take one argument, a list expression (a concept we don't have yet, see #9189 (comment), essentially just an expression in which you can only use pl.element()), which must return a scalar.

Then this would evaluate the expression for each list, returning the scalar. For example, to get the difference between the minimum and maximum in each list:

df.select(pl.col.l.list.agg(pl.element().max() - pl.element.min()))

Semantically this would be identical to the current-day:

df.select(pl.col.l.list.eval(pl.element().max() - pl.element.min()).list.first())

but it's cleaner to just write agg and allows us to ensure that you do indeed return a scalar for each list.

@orlp orlp added enhancement New feature or an improvement of an existing feature accepted Ready for implementation P-medium Priority: medium P-low Priority: low and removed P-medium Priority: medium labels May 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted Ready for implementation enhancement New feature or an improvement of an existing feature P-low Priority: low
Projects
None yet
Development

No branches or pull requests

1 participant