From 77188e0e04db70c7a1bb63008388791db37ed810 Mon Sep 17 00:00:00 2001 From: Richard Shadrach <45562402+rhshadrach@users.noreply.github.com> Date: Fri, 2 Feb 2024 17:54:29 -0500 Subject: [PATCH] DEPR: Enforce deprecation of groupby(...).grouper (#57207) --- 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 73776c2d6ee21..25163a0f678b0 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -103,6 +103,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`) diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index 68626534f1e74..64f882e5a146c 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -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]: diff --git a/pandas/core/groupby/grouper.py b/pandas/core/groupby/grouper.py index 4b9cf5ab75525..f377c9d03d05a 100644 --- a/pandas/core/groupby/grouper.py +++ b/pandas/core/groupby/grouper.py @@ -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): diff --git a/pandas/tests/groupby/test_grouping.py b/pandas/tests/groupby/test_grouping.py index 841dd29edab10..ee1df1242442f 100644 --- a/pandas/tests/groupby/test_grouping.py +++ b/pandas/tests/groupby/test_grouping.py @@ -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 result = sorted(grouper) expected = ["bar", "foo"] assert result == expected @@ -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) @@ -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 @@ -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