Skip to content

DEPR: Enforce deprecation of groupby(..., axis=1) #57186

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 5 commits into from
Feb 1, 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: 1 addition & 1 deletion doc/source/user_guide/groupby.rst
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ GroupBy object attributes
~~~~~~~~~~~~~~~~~~~~~~~~~

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

.. ipython:: python
Expand Down
6 changes: 3 additions & 3 deletions doc/source/user_guide/window.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ which will first group the data by the specified keys and then perform a windowi
.. versionadded:: 1.3.0

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

Expand Down
1 change: 1 addition & 0 deletions doc/source/whatsnew/v3.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ Deprecations
Removal of prior version deprecations/changes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- Removed :meth:`DataFrameGroupby.fillna` and :meth:`SeriesGroupBy.fillna` (:issue:`55719`)
- 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`)
- Removed the ``ArrayManager`` (:issue:`55043`)
Expand Down
21 changes: 0 additions & 21 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -9050,33 +9050,13 @@ def update(
def groupby(
self,
by=None,
axis: Axis | lib.NoDefault = lib.no_default,
level: IndexLabel | None = None,
as_index: bool = True,
sort: bool = True,
group_keys: bool = True,
observed: bool | lib.NoDefault = lib.no_default,
dropna: bool = True,
) -> DataFrameGroupBy:
if axis is not lib.no_default:
axis = self._get_axis_number(axis)
if axis == 1:
warnings.warn(
"DataFrame.groupby with axis=1 is deprecated. Do "
"`frame.T.groupby(...)` without axis instead.",
FutureWarning,
stacklevel=find_stack_level(),
)
else:
warnings.warn(
"The 'axis' keyword in DataFrame.groupby is deprecated and "
"will be removed in a future version.",
FutureWarning,
stacklevel=find_stack_level(),
)
else:
axis = 0

from pandas.core.groupby.generic import DataFrameGroupBy

if level is None and by is None:
Expand All @@ -9085,7 +9065,6 @@ def groupby(
return DataFrameGroupBy(
obj=self,
keys=by,
axis=axis,
level=level,
as_index=as_index,
sort=sort,
Expand Down
101 changes: 1 addition & 100 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -9366,7 +9366,6 @@ def between_time(
def resample(
self,
rule,
axis: Axis | lib.NoDefault = lib.no_default,
closed: Literal["right", "left"] | None = None,
label: Literal["right", "left"] | None = None,
convention: Literal["start", "end", "s", "e"] | lib.NoDefault = lib.no_default,
Expand All @@ -9389,13 +9388,6 @@ def resample(
----------
rule : DateOffset, Timedelta or str
The offset string or object representing target conversion.
axis : {{0 or 'index', 1 or 'columns'}}, default 0
Which axis to use for up- or down-sampling. For `Series` this parameter
is unused and defaults to 0. Must be
`DatetimeIndex`, `TimedeltaIndex` or `PeriodIndex`.

.. deprecated:: 2.0.0
Use frame.T.resample(...) instead.
closed : {{'right', 'left'}}, default None
Which side of bin interval is closed. The default is 'left'
for all frequency offsets except for 'ME', 'YE', 'QE', 'BME',
Expand Down Expand Up @@ -9707,25 +9699,6 @@ def resample(
"""
from pandas.core.resample import get_resampler

if axis is not lib.no_default:
axis = self._get_axis_number(axis)
if axis == 1:
warnings.warn(
"DataFrame.resample with axis=1 is deprecated. Do "
"`frame.T.resample(...)` without axis instead.",
FutureWarning,
stacklevel=find_stack_level(),
)
else:
warnings.warn(
f"The 'axis' keyword in {type(self).__name__}.resample is "
"deprecated and will be removed in a future version.",
FutureWarning,
stacklevel=find_stack_level(),
)
else:
axis = 0

if kind is not lib.no_default:
# GH#55895
warnings.warn(
Expand Down Expand Up @@ -9755,7 +9728,6 @@ def resample(
freq=rule,
label=label,
closed=closed,
axis=axis,
kind=kind,
convention=convention,
key=on,
Expand Down Expand Up @@ -12526,33 +12498,10 @@ def rolling(
center: bool_t = False,
win_type: str | None = None,
on: str | None = None,
axis: Axis | lib.NoDefault = lib.no_default,
closed: IntervalClosedType | None = None,
step: int | None = None,
method: str = "single",
) -> Window | Rolling:
if axis is not lib.no_default:
axis = self._get_axis_number(axis)
name = "rolling"
if axis == 1:
warnings.warn(
f"Support for axis=1 in {type(self).__name__}.{name} is "
"deprecated and will be removed in a future version. "
f"Use obj.T.{name}(...) instead",
FutureWarning,
stacklevel=find_stack_level(),
)
else:
warnings.warn(
f"The 'axis' keyword in {type(self).__name__}.{name} is "
"deprecated and will be removed in a future version. "
"Call the method without the axis keyword instead.",
FutureWarning,
stacklevel=find_stack_level(),
)
else:
axis = 0

if win_type is not None:
return Window(
self,
Expand All @@ -12561,7 +12510,6 @@ def rolling(
center=center,
win_type=win_type,
on=on,
axis=axis,
closed=closed,
step=step,
method=method,
Expand All @@ -12574,7 +12522,6 @@ def rolling(
center=center,
win_type=win_type,
on=on,
axis=axis,
closed=closed,
step=step,
method=method,
Expand All @@ -12585,31 +12532,9 @@ def rolling(
def expanding(
self,
min_periods: int = 1,
axis: Axis | lib.NoDefault = lib.no_default,
method: Literal["single", "table"] = "single",
) -> Expanding:
if axis is not lib.no_default:
axis = self._get_axis_number(axis)
name = "expanding"
if axis == 1:
warnings.warn(
f"Support for axis=1 in {type(self).__name__}.{name} is "
"deprecated and will be removed in a future version. "
f"Use obj.T.{name}(...) instead",
FutureWarning,
stacklevel=find_stack_level(),
)
else:
warnings.warn(
f"The 'axis' keyword in {type(self).__name__}.{name} is "
"deprecated and will be removed in a future version. "
"Call the method without the axis keyword instead.",
FutureWarning,
stacklevel=find_stack_level(),
)
else:
axis = 0
return Expanding(self, min_periods=min_periods, axis=axis, method=method)
return Expanding(self, min_periods=min_periods, method=method)

@final
@doc(ExponentialMovingWindow)
Expand All @@ -12622,32 +12547,9 @@ def ewm(
min_periods: int | None = 0,
adjust: bool_t = True,
ignore_na: bool_t = False,
axis: Axis | lib.NoDefault = lib.no_default,
times: np.ndarray | DataFrame | Series | None = None,
method: Literal["single", "table"] = "single",
) -> ExponentialMovingWindow:
if axis is not lib.no_default:
axis = self._get_axis_number(axis)
name = "ewm"
if axis == 1:
warnings.warn(
f"Support for axis=1 in {type(self).__name__}.{name} is "
"deprecated and will be removed in a future version. "
f"Use obj.T.{name}(...) instead",
FutureWarning,
stacklevel=find_stack_level(),
)
else:
warnings.warn(
f"The 'axis' keyword in {type(self).__name__}.{name} is "
"deprecated and will be removed in a future version. "
"Call the method without the axis keyword instead.",
FutureWarning,
stacklevel=find_stack_level(),
)
else:
axis = 0

return ExponentialMovingWindow(
self,
com=com,
Expand All @@ -12657,7 +12559,6 @@ def ewm(
min_periods=min_periods,
adjust=adjust,
ignore_na=ignore_na,
axis=axis,
times=times,
method=method,
)
Expand Down
Loading