Skip to content

Commit b397907

Browse files
rhshadrachpmhatre1
authored andcommitted
CLN: Enforce deprecation of DataFrameGroupBy.dtypes and Grouper attrs (pandas-dev#57756)
1 parent a876678 commit b397907

File tree

7 files changed

+2
-98
lines changed

7 files changed

+2
-98
lines changed

doc/source/whatsnew/v3.0.0.rst

+2
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,8 @@ Removal of prior version deprecations/changes
244244
- Removed the ``ordinal`` keyword in :class:`PeriodIndex`, use :meth:`PeriodIndex.from_ordinals` instead (:issue:`55960`)
245245
- Removed unused arguments ``*args`` and ``**kwargs`` in :class:`Resampler` methods (:issue:`50977`)
246246
- Unrecognized timezones when parsing strings to datetimes now raises a ``ValueError`` (:issue:`51477`)
247+
- Removed the :class:`Grouper` attributes ``ax``, ``groups``, ``indexer``, and ``obj`` (:issue:`51206`, :issue:`51182`)
248+
- Removed the attribute ``dtypes`` from :class:`.DataFrameGroupBy` (:issue:`51997`)
247249

248250
.. ---------------------------------------------------------------------------
249251
.. _whatsnew_300.performance:

pandas/core/groupby/base.py

-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ class OutputKey:
9090
"corr",
9191
"cov",
9292
"describe",
93-
"dtypes",
9493
"expanding",
9594
"ewm",
9695
"filter",

pandas/core/groupby/generic.py

-16
Original file line numberDiff line numberDiff line change
@@ -2706,22 +2706,6 @@ def hist(
27062706
)
27072707
return result
27082708

2709-
@property
2710-
@doc(DataFrame.dtypes.__doc__)
2711-
def dtypes(self) -> Series:
2712-
# GH#51045
2713-
warnings.warn(
2714-
f"{type(self).__name__}.dtypes is deprecated and will be removed in "
2715-
"a future version. Check the dtypes on the base object instead",
2716-
FutureWarning,
2717-
stacklevel=find_stack_level(),
2718-
)
2719-
2720-
# error: Incompatible return value type (got "DataFrame", expected "Series")
2721-
return self._python_apply_general( # type: ignore[return-value]
2722-
lambda df: df.dtypes, self._selected_obj
2723-
)
2724-
27252709
def corrwith(
27262710
self,
27272711
other: DataFrame | Series,

pandas/core/groupby/grouper.py

-52
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@
88
TYPE_CHECKING,
99
final,
1010
)
11-
import warnings
1211

1312
import numpy as np
1413

1514
from pandas._libs.tslibs import OutOfBoundsDatetime
1615
from pandas.errors import InvalidIndexError
1716
from pandas.util._decorators import cache_readonly
18-
from pandas.util._exceptions import find_stack_level
1917

2018
from pandas.core.dtypes.common import (
2119
is_list_like,
@@ -387,56 +385,6 @@ def _set_grouper(
387385
self._gpr_index = ax
388386
return obj, ax, indexer
389387

390-
@final
391-
@property
392-
def ax(self) -> Index:
393-
warnings.warn(
394-
f"{type(self).__name__}.ax is deprecated and will be removed in a "
395-
"future version. Use Resampler.ax instead",
396-
FutureWarning,
397-
stacklevel=find_stack_level(),
398-
)
399-
index = self._gpr_index
400-
if index is None:
401-
raise ValueError("_set_grouper must be called before ax is accessed")
402-
return index
403-
404-
@final
405-
@property
406-
def indexer(self):
407-
warnings.warn(
408-
f"{type(self).__name__}.indexer is deprecated and will be removed "
409-
"in a future version. Use Resampler.indexer instead.",
410-
FutureWarning,
411-
stacklevel=find_stack_level(),
412-
)
413-
return self._indexer_deprecated
414-
415-
@final
416-
@property
417-
def obj(self):
418-
# TODO(3.0): enforcing these deprecations on Grouper should close
419-
# GH#25564, GH#41930
420-
warnings.warn(
421-
f"{type(self).__name__}.obj is deprecated and will be removed "
422-
"in a future version. Use GroupBy.indexer instead.",
423-
FutureWarning,
424-
stacklevel=find_stack_level(),
425-
)
426-
return self._obj_deprecated
427-
428-
@final
429-
@property
430-
def groups(self):
431-
warnings.warn(
432-
f"{type(self).__name__}.groups is deprecated and will be removed "
433-
"in a future version. Use GroupBy.groups instead.",
434-
FutureWarning,
435-
stacklevel=find_stack_level(),
436-
)
437-
# error: "None" has no attribute "groups"
438-
return self._grouper_deprecated.groups # type: ignore[attr-defined]
439-
440388
@final
441389
def __repr__(self) -> str:
442390
attrs_list = (

pandas/tests/groupby/test_api.py

-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ def test_tab_completion(multiindex_dataframe_random_data):
8080
"corr",
8181
"corrwith",
8282
"cov",
83-
"dtypes",
8483
"ndim",
8584
"diff",
8685
"idxmax",

pandas/tests/groupby/test_groupby.py

-3
Original file line numberDiff line numberDiff line change
@@ -2828,9 +2828,6 @@ def test_groupby_selection_other_methods(df):
28282828
g_exp = df[["C"]].groupby(df["A"])
28292829

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

28362833
tm.assert_frame_equal(g.resample("D").mean(), g_exp.resample("D").mean())

pandas/tests/groupby/test_grouping.py

-25
Original file line numberDiff line numberDiff line change
@@ -1128,28 +1128,3 @@ def test_grouping_by_key_is_in_axis():
11281128
result = gb.sum()
11291129
expected = DataFrame({"a": [1, 2], "b": [1, 2], "c": [7, 5]})
11301130
tm.assert_frame_equal(result, expected)
1131-
1132-
1133-
def test_grouper_groups():
1134-
# GH#51182 check Grouper.groups does not raise AttributeError
1135-
df = DataFrame({"a": [1, 2, 3], "b": 1})
1136-
grper = Grouper(key="a")
1137-
gb = df.groupby(grper)
1138-
1139-
msg = "Use GroupBy.groups instead"
1140-
with tm.assert_produces_warning(FutureWarning, match=msg):
1141-
res = grper.groups
1142-
assert res is gb.groups
1143-
1144-
msg = "Grouper.obj is deprecated and will be removed"
1145-
with tm.assert_produces_warning(FutureWarning, match=msg):
1146-
res = grper.obj
1147-
assert res is gb.obj
1148-
1149-
msg = "Use Resampler.ax instead"
1150-
with tm.assert_produces_warning(FutureWarning, match=msg):
1151-
grper.ax
1152-
1153-
msg = "Grouper.indexer is deprecated"
1154-
with tm.assert_produces_warning(FutureWarning, match=msg):
1155-
grper.indexer

0 commit comments

Comments
 (0)