Skip to content
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

docs: Update group_by_dynamic example #11737

Merged
merged 2 commits into from
Oct 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,11 @@
.to_frame()
)

out = (
df.group_by_dynamic("time", every="1mo", period="1mo", closed="left")
.agg(
[
pl.col("time").cumcount().reverse().head(3).alias("day/eom"),
((pl.col("time") - pl.col("time").first()).last().dt.days() + 1).alias(
"days_in_month"
),
]
)
.explode("day/eom")
out = df.group_by_dynamic("time", every="1mo", period="1mo", closed="left").agg(
pl.col("time").cumcount().reverse().head(3).alias("day/eom"),
((pl.col("time") - pl.col("time").first()).last().dt.days() + 1).alias(
"days_in_month"
),
)
print(out)
# --8<-- [end:group_by_dyn]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
) + lit(1))
.alias("days_in_month"),
])
.explode([col("day/eom")])
.collect()?;
println!("{}", &out);
// --8<-- [end:group_by_dyn]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Computation
Expr.cbrt
Expr.cos
Expr.cosh
Expr.cot
Expr.cumcount
Expr.cummax
Expr.cummin
Expand Down
1 change: 1 addition & 0 deletions py-polars/docs/source/reference/series/computation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Computation
Series.cbrt
Series.cos
Series.cosh
Series.cot
Series.cummax
Series.cummin
Series.cumprod
Expand Down