From 5d0df483fde9232520e8081e9bb6b04c33231155 Mon Sep 17 00:00:00 2001 From: richard Date: Thu, 1 Feb 2024 22:30:50 -0500 Subject: [PATCH] DEPR: Enforce deprecation of groupby(...).grouper --- doc/source/whatsnew/v3.0.0.rst | 1 + pandas/core/groupby/groupby.py | 11 ----------- pandas/core/groupby/grouper.py | 11 ----------- pandas/tests/groupby/test_grouping.py | 17 +++-------------- 4 files changed, 4 insertions(+), 36 deletions(-) diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index f316f6b44c1b4..7a4f158586bd9 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -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 all groupby operations (:issue:`50405`) - Removed deprecated argument ``obj`` in :meth:`.DataFrameGroupBy.get_group` and :meth:`.SeriesGroupBy.get_group` (:issue:`53545`) - Removed the ``ArrayManager`` (:issue:`55043`) diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index 1f0e0567446c6..7bee17bd9fbd5 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -802,17 +802,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]: diff --git a/pandas/core/groupby/grouper.py b/pandas/core/groupby/grouper.py index 08ee786170674..ef1ab947ec0a6 100644 --- a/pandas/core/groupby/grouper.py +++ b/pandas/core/groupby/grouper.py @@ -450,17 +450,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): diff --git a/pandas/tests/groupby/test_grouping.py b/pandas/tests/groupby/test_grouping.py index 39d1ba207fba7..135e8bae75b42 100644 --- a/pandas/tests/groupby/test_grouping.py +++ b/pandas/tests/groupby/test_grouping.py @@ -429,9 +429,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 result = sorted(grouper) expected = ["bar", "foo"] assert result == expected @@ -443,9 +441,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) @@ -833,9 +829,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 @@ -1205,11 +1199,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