Skip to content

Commit 24f7db7

Browse files
authored
DEPR: Enforce deprecation of groupby(..., axis=1) (#57186)
* DEPR: Enforce deprecation of groupby(..., axis=1) * More removals and cleanups * whatsnew
1 parent 965a65b commit 24f7db7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+213
-1825
lines changed

doc/source/user_guide/groupby.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ GroupBy object attributes
247247
~~~~~~~~~~~~~~~~~~~~~~~~~
248248

249249
The ``groups`` attribute is a dictionary whose keys are the computed unique groups
250-
and corresponding values are the axis labels belonging to each group. In the
250+
and corresponding values are the index labels belonging to each group. In the
251251
above example we have:
252252

253253
.. ipython:: python

doc/source/user_guide/window.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ which will first group the data by the specified keys and then perform a windowi
7979
.. versionadded:: 1.3.0
8080

8181
Some windowing operations also support the ``method='table'`` option in the constructor which
82-
performs the windowing operation over an entire :class:`DataFrame` instead of a single column or row at a time.
83-
This can provide a useful performance benefit for a :class:`DataFrame` with many columns or rows
84-
(with the corresponding ``axis`` argument) or the ability to utilize other columns during the windowing
82+
performs the windowing operation over an entire :class:`DataFrame` instead of a single column at a time.
83+
This can provide a useful performance benefit for a :class:`DataFrame` with many columns
84+
or the ability to utilize other columns during the windowing
8585
operation. The ``method='table'`` option can only be used if ``engine='numba'`` is specified
8686
in the corresponding method call.
8787

doc/source/whatsnew/v3.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ Deprecations
102102
Removal of prior version deprecations/changes
103103
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
104104
- Removed :meth:`DataFrameGroupby.fillna` and :meth:`SeriesGroupBy.fillna` (:issue:`55719`)
105+
- 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`)
105106
- Removed ``axis`` argument from all groupby operations (:issue:`50405`)
106107
- Removed deprecated argument ``obj`` in :meth:`.DataFrameGroupBy.get_group` and :meth:`.SeriesGroupBy.get_group` (:issue:`53545`)
107108
- Removed the ``ArrayManager`` (:issue:`55043`)

pandas/core/frame.py

-21
Original file line numberDiff line numberDiff line change
@@ -9050,33 +9050,13 @@ def update(
90509050
def groupby(
90519051
self,
90529052
by=None,
9053-
axis: Axis | lib.NoDefault = lib.no_default,
90549053
level: IndexLabel | None = None,
90559054
as_index: bool = True,
90569055
sort: bool = True,
90579056
group_keys: bool = True,
90589057
observed: bool | lib.NoDefault = lib.no_default,
90599058
dropna: bool = True,
90609059
) -> DataFrameGroupBy:
9061-
if axis is not lib.no_default:
9062-
axis = self._get_axis_number(axis)
9063-
if axis == 1:
9064-
warnings.warn(
9065-
"DataFrame.groupby with axis=1 is deprecated. Do "
9066-
"`frame.T.groupby(...)` without axis instead.",
9067-
FutureWarning,
9068-
stacklevel=find_stack_level(),
9069-
)
9070-
else:
9071-
warnings.warn(
9072-
"The 'axis' keyword in DataFrame.groupby is deprecated and "
9073-
"will be removed in a future version.",
9074-
FutureWarning,
9075-
stacklevel=find_stack_level(),
9076-
)
9077-
else:
9078-
axis = 0
9079-
90809060
from pandas.core.groupby.generic import DataFrameGroupBy
90819061

90829062
if level is None and by is None:
@@ -9085,7 +9065,6 @@ def groupby(
90859065
return DataFrameGroupBy(
90869066
obj=self,
90879067
keys=by,
9088-
axis=axis,
90899068
level=level,
90909069
as_index=as_index,
90919070
sort=sort,

pandas/core/generic.py

+1-100
Original file line numberDiff line numberDiff line change
@@ -9351,7 +9351,6 @@ def between_time(
93519351
def resample(
93529352
self,
93539353
rule,
9354-
axis: Axis | lib.NoDefault = lib.no_default,
93559354
closed: Literal["right", "left"] | None = None,
93569355
label: Literal["right", "left"] | None = None,
93579356
convention: Literal["start", "end", "s", "e"] | lib.NoDefault = lib.no_default,
@@ -9374,13 +9373,6 @@ def resample(
93749373
----------
93759374
rule : DateOffset, Timedelta or str
93769375
The offset string or object representing target conversion.
9377-
axis : {{0 or 'index', 1 or 'columns'}}, default 0
9378-
Which axis to use for up- or down-sampling. For `Series` this parameter
9379-
is unused and defaults to 0. Must be
9380-
`DatetimeIndex`, `TimedeltaIndex` or `PeriodIndex`.
9381-
9382-
.. deprecated:: 2.0.0
9383-
Use frame.T.resample(...) instead.
93849376
closed : {{'right', 'left'}}, default None
93859377
Which side of bin interval is closed. The default is 'left'
93869378
for all frequency offsets except for 'ME', 'YE', 'QE', 'BME',
@@ -9692,25 +9684,6 @@ def resample(
96929684
"""
96939685
from pandas.core.resample import get_resampler
96949686

9695-
if axis is not lib.no_default:
9696-
axis = self._get_axis_number(axis)
9697-
if axis == 1:
9698-
warnings.warn(
9699-
"DataFrame.resample with axis=1 is deprecated. Do "
9700-
"`frame.T.resample(...)` without axis instead.",
9701-
FutureWarning,
9702-
stacklevel=find_stack_level(),
9703-
)
9704-
else:
9705-
warnings.warn(
9706-
f"The 'axis' keyword in {type(self).__name__}.resample is "
9707-
"deprecated and will be removed in a future version.",
9708-
FutureWarning,
9709-
stacklevel=find_stack_level(),
9710-
)
9711-
else:
9712-
axis = 0
9713-
97149687
if kind is not lib.no_default:
97159688
# GH#55895
97169689
warnings.warn(
@@ -9740,7 +9713,6 @@ def resample(
97409713
freq=rule,
97419714
label=label,
97429715
closed=closed,
9743-
axis=axis,
97449716
kind=kind,
97459717
convention=convention,
97469718
key=on,
@@ -12511,33 +12483,10 @@ def rolling(
1251112483
center: bool_t = False,
1251212484
win_type: str | None = None,
1251312485
on: str | None = None,
12514-
axis: Axis | lib.NoDefault = lib.no_default,
1251512486
closed: IntervalClosedType | None = None,
1251612487
step: int | None = None,
1251712488
method: str = "single",
1251812489
) -> Window | Rolling:
12519-
if axis is not lib.no_default:
12520-
axis = self._get_axis_number(axis)
12521-
name = "rolling"
12522-
if axis == 1:
12523-
warnings.warn(
12524-
f"Support for axis=1 in {type(self).__name__}.{name} is "
12525-
"deprecated and will be removed in a future version. "
12526-
f"Use obj.T.{name}(...) instead",
12527-
FutureWarning,
12528-
stacklevel=find_stack_level(),
12529-
)
12530-
else:
12531-
warnings.warn(
12532-
f"The 'axis' keyword in {type(self).__name__}.{name} is "
12533-
"deprecated and will be removed in a future version. "
12534-
"Call the method without the axis keyword instead.",
12535-
FutureWarning,
12536-
stacklevel=find_stack_level(),
12537-
)
12538-
else:
12539-
axis = 0
12540-
1254112490
if win_type is not None:
1254212491
return Window(
1254312492
self,
@@ -12546,7 +12495,6 @@ def rolling(
1254612495
center=center,
1254712496
win_type=win_type,
1254812497
on=on,
12549-
axis=axis,
1255012498
closed=closed,
1255112499
step=step,
1255212500
method=method,
@@ -12559,7 +12507,6 @@ def rolling(
1255912507
center=center,
1256012508
win_type=win_type,
1256112509
on=on,
12562-
axis=axis,
1256312510
closed=closed,
1256412511
step=step,
1256512512
method=method,
@@ -12570,31 +12517,9 @@ def rolling(
1257012517
def expanding(
1257112518
self,
1257212519
min_periods: int = 1,
12573-
axis: Axis | lib.NoDefault = lib.no_default,
1257412520
method: Literal["single", "table"] = "single",
1257512521
) -> Expanding:
12576-
if axis is not lib.no_default:
12577-
axis = self._get_axis_number(axis)
12578-
name = "expanding"
12579-
if axis == 1:
12580-
warnings.warn(
12581-
f"Support for axis=1 in {type(self).__name__}.{name} is "
12582-
"deprecated and will be removed in a future version. "
12583-
f"Use obj.T.{name}(...) instead",
12584-
FutureWarning,
12585-
stacklevel=find_stack_level(),
12586-
)
12587-
else:
12588-
warnings.warn(
12589-
f"The 'axis' keyword in {type(self).__name__}.{name} is "
12590-
"deprecated and will be removed in a future version. "
12591-
"Call the method without the axis keyword instead.",
12592-
FutureWarning,
12593-
stacklevel=find_stack_level(),
12594-
)
12595-
else:
12596-
axis = 0
12597-
return Expanding(self, min_periods=min_periods, axis=axis, method=method)
12522+
return Expanding(self, min_periods=min_periods, method=method)
1259812523

1259912524
@final
1260012525
@doc(ExponentialMovingWindow)
@@ -12607,32 +12532,9 @@ def ewm(
1260712532
min_periods: int | None = 0,
1260812533
adjust: bool_t = True,
1260912534
ignore_na: bool_t = False,
12610-
axis: Axis | lib.NoDefault = lib.no_default,
1261112535
times: np.ndarray | DataFrame | Series | None = None,
1261212536
method: Literal["single", "table"] = "single",
1261312537
) -> ExponentialMovingWindow:
12614-
if axis is not lib.no_default:
12615-
axis = self._get_axis_number(axis)
12616-
name = "ewm"
12617-
if axis == 1:
12618-
warnings.warn(
12619-
f"Support for axis=1 in {type(self).__name__}.{name} is "
12620-
"deprecated and will be removed in a future version. "
12621-
f"Use obj.T.{name}(...) instead",
12622-
FutureWarning,
12623-
stacklevel=find_stack_level(),
12624-
)
12625-
else:
12626-
warnings.warn(
12627-
f"The 'axis' keyword in {type(self).__name__}.{name} is "
12628-
"deprecated and will be removed in a future version. "
12629-
"Call the method without the axis keyword instead.",
12630-
FutureWarning,
12631-
stacklevel=find_stack_level(),
12632-
)
12633-
else:
12634-
axis = 0
12635-
1263612538
return ExponentialMovingWindow(
1263712539
self,
1263812540
com=com,
@@ -12642,7 +12544,6 @@ def ewm(
1264212544
min_periods=min_periods,
1264312545
adjust=adjust,
1264412546
ignore_na=ignore_na,
12645-
axis=axis,
1264612547
times=times,
1264712548
method=method,
1264812549
)

0 commit comments

Comments
 (0)