We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
group_by
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
If a group_by key is a literal it could be removed from the grouping. For example, before:
>>> df = pl.DataFrame({"x": [1, 2, 3], "g": [1, 1, 2]}) >>> df.group_by([pl.lit(1), "g"]).agg(pl.col.x.sum()) shape: (2, 3) ┌─────────┬─────┬─────┐ │ literal ┆ g ┆ x │ │ --- ┆ --- ┆ --- │ │ i32 ┆ i64 ┆ i64 │ ╞═════════╪═════╪═════╡ │ 1 ┆ 1 ┆ 3 │ │ 1 ┆ 2 ┆ 3 │ └─────────┴─────┴─────┘
After:
>>> df = pl.DataFrame({"x": [1, 2, 3], "g": [1, 1, 2]}) >>> df.group_by("g").agg(pl.col.x.sum()).select(pl.lit(1), pl.col.g, pl.col.x) shape: (2, 3) ┌─────────┬─────┬─────┐ │ literal ┆ g ┆ x │ │ --- ┆ --- ┆ --- │ │ i32 ┆ i64 ┆ i64 │ ╞═════════╪═════╪═════╡ │ 1 ┆ 1 ┆ 3 │ │ 1 ┆ 2 ┆ 3 │ └─────────┴─────┴─────┘
In the event that the literal is the only grouping key, the entire .agg should be rewritten to a select.
.agg
The text was updated successfully, but these errors were encountered:
No branches or pull requests
If a
group_by
key is a literal it could be removed from the grouping. For example, before:After:
In the event that the literal is the only grouping key, the entire
.agg
should be rewritten to a select.The text was updated successfully, but these errors were encountered: