Skip to content

Commit

Permalink
docs: Update group_by_dynamic example (#11737)
Browse files Browse the repository at this point in the history
  • Loading branch information
stinodego authored Oct 14, 2023
1 parent 55c9f8f commit 95b4480
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 12 deletions.
16 changes: 5 additions & 11 deletions docs/src/python/user-guide/transformations/time-series/rolling.py
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

0 comments on commit 95b4480

Please sign in to comment.