Skip to content

Commit

Permalink
python: groupby_dynamic closed left (#4332)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Aug 9, 2022
1 parent fb971a2 commit ead3f52
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
11 changes: 6 additions & 5 deletions py-polars/polars/internals/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2963,7 +2963,7 @@ def groupby_dynamic(
offset: str | None = None,
truncate: bool = True,
include_boundaries: bool = False,
closed: ClosedWindow = "right",
closed: ClosedWindow = "left",
by: str | list[str] | pli.Expr | list[pli.Expr] | None = None,
) -> DynamicGroupBy[DF]:
"""
Expand Down Expand Up @@ -3071,7 +3071,7 @@ def groupby_dynamic(
Group by windows of 1 hour starting at 2021-12-16 00:00:00.
>>> (
... df.groupby_dynamic("time", every="1h").agg(
... df.groupby_dynamic("time", every="1h", closed="right").agg(
... [
... pl.col("time").min().alias("time_min"),
... pl.col("time").max().alias("time_max"),
Expand All @@ -3096,9 +3096,9 @@ def groupby_dynamic(
The window boundaries can also be added to the aggregation result
>>> (
... df.groupby_dynamic("time", every="1h", include_boundaries=True).agg(
... [pl.col("time").count().alias("time_count")]
... )
... df.groupby_dynamic(
... "time", every="1h", include_boundaries=True, closed="right"
... ).agg([pl.col("time").count().alias("time_count")])
... )
shape: (4, 4)
┌─────────────────────┬─────────────────────┬─────────────────────┬────────────┐
Expand Down Expand Up @@ -3243,6 +3243,7 @@ def groupby_dynamic(
... every="2i",
... period="3i",
... include_boundaries=True,
... closed="right",
... ).agg(pl.col("A").list().alias("A_agg_list"))
... )
shape: (3, 4)
Expand Down
2 changes: 1 addition & 1 deletion py-polars/polars/internals/lazy_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1100,7 +1100,7 @@ def groupby_dynamic(
offset: str | None = None,
truncate: bool = True,
include_boundaries: bool = False,
closed: ClosedWindow = "right",
closed: ClosedWindow = "left",
by: str | list[str] | pli.Expr | list[pli.Expr] | None = None,
) -> LazyGroupBy[LDF]:
"""
Expand Down
4 changes: 2 additions & 2 deletions py-polars/tests/test_df.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ def test_groupby_dynamic_agg_input_types(lazy: bool) -> None:
for bad_param in BAD_AGG_PARAMETERS:
with pytest.raises(TypeError):
result = df_or_lazy.groupby_dynamic(
index_column="index_column", every="2i"
index_column="index_column", every="2i", closed="right"
).agg(
bad_param # type: ignore[arg-type]
)
Expand All @@ -464,7 +464,7 @@ def test_groupby_dynamic_agg_input_types(lazy: bool) -> None:

for good_param in GOOD_AGG_PARAMETERS:
result = df_or_lazy.groupby_dynamic(
index_column="index_column", every="2i"
index_column="index_column", every="2i", closed="right"
).agg(good_param)
if lazy:
result = result.collect() # type: ignore[union-attr]
Expand Down

0 comments on commit ead3f52

Please sign in to comment.