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

DEPR: Enforce deprecation of groupby(...).grouper #57207

Merged
merged 2 commits into from
Feb 2, 2024
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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v3.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ Deprecations
Removal of prior version deprecations/changes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- Removed :meth:`DataFrameGroupby.fillna` and :meth:`SeriesGroupBy.fillna` (:issue:`55719`)
- Removed ``DataFrameGroupBy.grouper`` and ``SeriesGroupBy.grouper`` (:issue:`56521`)
- Removed ``axis`` argument from :meth:`DataFrame.groupby`, :meth:`Series.groupby`, :meth:`DataFrame.rolling`, :meth:`Series.rolling`, :meth:`DataFrame.resample`, and :meth:`Series.resample` (:issue:`51203`)
- Removed ``axis`` argument from all groupby operations (:issue:`50405`)
- Removed deprecated argument ``obj`` in :meth:`.DataFrameGroupBy.get_group` and :meth:`.SeriesGroupBy.get_group` (:issue:`53545`)
Expand Down
11 changes: 0 additions & 11 deletions pandas/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -794,17 +794,6 @@ def __repr__(self) -> str:
# TODO: Better repr for GroupBy object
return object.__repr__(self)

@final
@property
def grouper(self) -> ops.BaseGrouper:
warnings.warn(
f"{type(self).__name__}.grouper is deprecated and will be removed in a "
"future version of pandas.",
category=FutureWarning,
stacklevel=find_stack_level(),
)
return self._grouper

@final
@property
def groups(self) -> dict[Hashable, np.ndarray]:
Expand Down
11 changes: 0 additions & 11 deletions pandas/core/groupby/grouper.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,17 +428,6 @@ def obj(self):
)
return self._obj_deprecated

@final
@property
def grouper(self):
warnings.warn(
f"{type(self).__name__}.grouper is deprecated and will be removed "
"in a future version. Use GroupBy.grouper instead.",
FutureWarning,
stacklevel=find_stack_level(),
)
return self._grouper_deprecated

@final
@property
def groups(self):
Expand Down
17 changes: 3 additions & 14 deletions pandas/tests/groupby/test_grouping.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,9 +414,7 @@ def test_grouper_getting_correct_binner(self):

def test_grouper_iter(self, df):
gb = df.groupby("A")
msg = "DataFrameGroupBy.grouper is deprecated"
with tm.assert_produces_warning(FutureWarning, match=msg):
grouper = gb.grouper
grouper = gb._grouper
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these _grouper usages common internally? If not, I would be OK just removing these tests

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking as long as the method exists, we should leave the tests - especially if they aren't computationally intensive. That said, it appears we never use __iter__, so could be removed. I'd like to handle in a follow up. I'll open an issue and list out methods we can remove.

result = sorted(grouper)
expected = ["bar", "foo"]
assert result == expected
Expand All @@ -428,9 +426,7 @@ def test_empty_groups(self, df):

def test_groupby_grouper(self, df):
grouped = df.groupby("A")
msg = "DataFrameGroupBy.grouper is deprecated"
with tm.assert_produces_warning(FutureWarning, match=msg):
grouper = grouped.grouper
grouper = grouped._grouper
result = df.groupby(grouper).mean(numeric_only=True)
expected = grouped.mean(numeric_only=True)
tm.assert_frame_equal(result, expected)
Expand Down Expand Up @@ -791,9 +787,7 @@ def test_groupby_empty(self):

# check name
gb = s.groupby(s)
msg = "SeriesGroupBy.grouper is deprecated"
with tm.assert_produces_warning(FutureWarning, match=msg):
grouper = gb.grouper
grouper = gb._grouper
result = grouper.names
expected = ["name"]
assert result == expected
Expand Down Expand Up @@ -1155,11 +1149,6 @@ def test_grouper_groups():
res = grper.groups
assert res is gb.groups

msg = "Use GroupBy.grouper instead"
with tm.assert_produces_warning(FutureWarning, match=msg):
res = grper.grouper
assert res is gb._grouper

msg = "Grouper.obj is deprecated and will be removed"
with tm.assert_produces_warning(FutureWarning, match=msg):
res = grper.obj
Expand Down
Loading