Skip to content

CLN: Enforce deprecation of DataFrameGroupBy.dtypes and Grouper attrs #57756

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

Merged
merged 1 commit into from
Mar 7, 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
2 changes: 2 additions & 0 deletions doc/source/whatsnew/v3.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ Removal of prior version deprecations/changes
- Removed the ``ordinal`` keyword in :class:`PeriodIndex`, use :meth:`PeriodIndex.from_ordinals` instead (:issue:`55960`)
- Removed unused arguments ``*args`` and ``**kwargs`` in :class:`Resampler` methods (:issue:`50977`)
- Unrecognized timezones when parsing strings to datetimes now raises a ``ValueError`` (:issue:`51477`)
- Removed the :class:`Grouper` attributes ``ax``, ``groups``, ``indexer``, and ``obj`` (:issue:`51206`, :issue:`51182`)
- Removed the attribute ``dtypes`` from :class:`.DataFrameGroupBy` (:issue:`51997`)

.. ---------------------------------------------------------------------------
.. _whatsnew_300.performance:
Expand Down
1 change: 0 additions & 1 deletion pandas/core/groupby/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ class OutputKey:
"corr",
"cov",
"describe",
"dtypes",
"expanding",
"ewm",
"filter",
Expand Down
16 changes: 0 additions & 16 deletions pandas/core/groupby/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2720,22 +2720,6 @@ def hist(
)
return result

@property
@doc(DataFrame.dtypes.__doc__)
def dtypes(self) -> Series:
# GH#51045
warnings.warn(
f"{type(self).__name__}.dtypes is deprecated and will be removed in "
"a future version. Check the dtypes on the base object instead",
FutureWarning,
stacklevel=find_stack_level(),
)

# error: Incompatible return value type (got "DataFrame", expected "Series")
return self._python_apply_general( # type: ignore[return-value]
lambda df: df.dtypes, self._selected_obj
)

def corrwith(
self,
other: DataFrame | Series,
Expand Down
52 changes: 0 additions & 52 deletions pandas/core/groupby/grouper.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@
TYPE_CHECKING,
final,
)
import warnings

import numpy as np

from pandas._libs.tslibs import OutOfBoundsDatetime
from pandas.errors import InvalidIndexError
from pandas.util._decorators import cache_readonly
from pandas.util._exceptions import find_stack_level

from pandas.core.dtypes.common import (
is_list_like,
Expand Down Expand Up @@ -387,56 +385,6 @@ def _set_grouper(
self._gpr_index = ax
return obj, ax, indexer

@final
@property
def ax(self) -> Index:
warnings.warn(
f"{type(self).__name__}.ax is deprecated and will be removed in a "
"future version. Use Resampler.ax instead",
FutureWarning,
stacklevel=find_stack_level(),
)
index = self._gpr_index
if index is None:
raise ValueError("_set_grouper must be called before ax is accessed")
return index

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

@final
@property
def obj(self):
# TODO(3.0): enforcing these deprecations on Grouper should close
# GH#25564, GH#41930
warnings.warn(
f"{type(self).__name__}.obj is deprecated and will be removed "
"in a future version. Use GroupBy.indexer instead.",
FutureWarning,
stacklevel=find_stack_level(),
)
return self._obj_deprecated

@final
@property
def groups(self):
warnings.warn(
f"{type(self).__name__}.groups is deprecated and will be removed "
"in a future version. Use GroupBy.groups instead.",
FutureWarning,
stacklevel=find_stack_level(),
)
# error: "None" has no attribute "groups"
return self._grouper_deprecated.groups # type: ignore[attr-defined]

@final
def __repr__(self) -> str:
attrs_list = (
Expand Down
1 change: 0 additions & 1 deletion pandas/tests/groupby/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ def test_tab_completion(multiindex_dataframe_random_data):
"corr",
"corrwith",
"cov",
"dtypes",
"ndim",
"diff",
"idxmax",
Expand Down
3 changes: 0 additions & 3 deletions pandas/tests/groupby/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -2828,9 +2828,6 @@ def test_groupby_selection_other_methods(df):
g_exp = df[["C"]].groupby(df["A"])

# methods which aren't just .foo()
msg = "DataFrameGroupBy.dtypes is deprecated"
with tm.assert_produces_warning(FutureWarning, match=msg):
tm.assert_frame_equal(g.dtypes, g_exp.dtypes)
tm.assert_frame_equal(g.apply(lambda x: x.sum()), g_exp.apply(lambda x: x.sum()))

tm.assert_frame_equal(g.resample("D").mean(), g_exp.resample("D").mean())
Expand Down
25 changes: 0 additions & 25 deletions pandas/tests/groupby/test_grouping.py
Original file line number Diff line number Diff line change
Expand Up @@ -1128,28 +1128,3 @@ def test_grouping_by_key_is_in_axis():
result = gb.sum()
expected = DataFrame({"a": [1, 2], "b": [1, 2], "c": [7, 5]})
tm.assert_frame_equal(result, expected)


def test_grouper_groups():
# GH#51182 check Grouper.groups does not raise AttributeError
df = DataFrame({"a": [1, 2, 3], "b": 1})
grper = Grouper(key="a")
gb = df.groupby(grper)

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

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

msg = "Use Resampler.ax instead"
with tm.assert_produces_warning(FutureWarning, match=msg):
grper.ax

msg = "Grouper.indexer is deprecated"
with tm.assert_produces_warning(FutureWarning, match=msg):
grper.indexer