Skip to content

Commit

Permalink
chore(python): Properly deprecate GroupBy.agg_list (#6943)
Browse files Browse the repository at this point in the history
  • Loading branch information
stinodego authored Feb 16, 2023
1 parent e705e3a commit d94688d
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 29 deletions.
27 changes: 2 additions & 25 deletions py-polars/polars/internals/dataframe/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
)

import polars.internals as pli
from polars.utils import _timedelta_to_pl_duration
from polars.utils import _timedelta_to_pl_duration, redirect

if TYPE_CHECKING:
from polars.internals.type_aliases import (
Expand All @@ -26,6 +26,7 @@
DF = TypeVar("DF", bound="pli.DataFrame")


@redirect({"agg_list": "all"})
class GroupBy(Generic[DF]):
"""Starts a new GroupBy operation."""

Expand Down Expand Up @@ -674,30 +675,6 @@ def median(self) -> pli.DataFrame:
"""
return self.agg(pli.all().median())

def agg_list(self) -> pli.DataFrame:
"""
Aggregate the groups into Series.
.. deprecated:: 0.16.0
Use ```all()``
Examples
--------
>>> df = pl.DataFrame({"a": ["one", "two", "one", "two"], "b": [1, 2, 3, 4]})
>>> df.groupby("a", maintain_order=True).agg_list()
shape: (2, 2)
┌─────┬───────────┐
│ a ┆ b │
│ --- ┆ --- │
│ str ┆ list[i64] │
╞═════╪═══════════╡
│ one ┆ [1, 3] │
│ two ┆ [2, 4] │
└─────┴───────────┘
"""
return self.agg(pli.all())

def all(self) -> pli.DataFrame:
"""
Aggregate the groups into Series.
Expand Down
2 changes: 1 addition & 1 deletion py-polars/tests/unit/test_df.py
Original file line number Diff line number Diff line change
Expand Up @@ -1694,7 +1694,7 @@ def test_groupby_order_dispatch() -> None:
)
assert_frame_equal(result, expected)

result = df.groupby("x", maintain_order=True).agg_list()
result = df.groupby("x", maintain_order=True).all()
expected = pl.DataFrame({"x": ["b", "a"], "y": [[0, 2], [1]]})
assert_frame_equal(result, expected)

Expand Down
2 changes: 1 addition & 1 deletion py-polars/tests/unit/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def test_groupby() -> None:
assert sorted(df.groupby("b").mean().rows()) == [("a", 1.5, 1.0), ("b", 4.0, 1.0)]
assert sorted(df.groupby("b").n_unique().rows()) == [("a", 2, 2), ("b", 3, 2)]
assert sorted(df.groupby("b").median().rows()) == [("a", 1.5, 1.0), ("b", 4.0, 1.0)]
assert sorted(df.groupby("b").agg_list().rows()) == [
assert sorted(df.groupby("b").all().rows()) == [
("a", [1, 2], [None, 1]),
("b", [3, 4, 5], [None, 1, None]),
]
Expand Down
4 changes: 2 additions & 2 deletions py-polars/tests/unit/test_struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ def test_struct_list_head_tail() -> None:
}


def test_struct_agg_list() -> None:
def test_struct_agg_all() -> None:
df = pl.DataFrame(
{
"group": ["a", "a", "b", "b", "b"],
Expand All @@ -342,7 +342,7 @@ def test_struct_agg_list() -> None:
}
)

assert df.groupby("group", maintain_order=True).agg_list().to_dict(False) == {
assert df.groupby("group", maintain_order=True).all().to_dict(False) == {
"group": ["a", "b"],
"col1": [
[{"x": 1, "y": 100}, {"x": 2, "y": 200}],
Expand Down

0 comments on commit d94688d

Please sign in to comment.