Skip to content
Open
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
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 @@ -717,6 +717,7 @@ Other Deprecations
- Deprecated allowing ``fill_value`` that cannot be held in the original dtype (excepting NA values for integer and bool dtypes) in :meth:`Series.unstack` and :meth:`DataFrame.unstack` (:issue:`12189`, :issue:`53868`)
- Deprecated allowing ``fill_value`` that cannot be held in the original dtype (excepting NA values for integer and bool dtypes) in :meth:`Series.shift` and :meth:`DataFrame.shift` (:issue:`53802`)
- Deprecated slicing on a :class:`Series` or :class:`DataFrame` with a :class:`DatetimeIndex` using a ``datetime.date`` object, explicitly cast to :class:`Timestamp` instead (:issue:`35830`)
- Deprecated the "columns" keyword in :meth:`Series.drop` as it was silently ignored (:issue:`39509`)

.. ---------------------------------------------------------------------------
.. _whatsnew_300.prior_deprecations:
Expand Down
6 changes: 5 additions & 1 deletion pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
from pandas.util._decorators import (
Appender,
Substitution,
deprecate_kwarg,
deprecate_nonkeyword_arguments,
doc,
set_module,
Expand Down Expand Up @@ -5064,6 +5065,7 @@ def drop(
errors: IgnoreRaise = ...,
) -> Series | None: ...

@deprecate_kwarg(Pandas4Warning, "columns", new_arg_name=None) # GH#39509
def drop(
self,
labels: IndexLabel | ListLike = None,
Expand Down Expand Up @@ -5092,7 +5094,9 @@ def drop(
Redundant for application on Series, but 'index' can be used instead
of 'labels'.
columns : single label or list-like
No change is made to the Series; use 'index' or 'labels' instead.
Not supported; use 'index' or 'labels' instead.
.. deprecated:: 3.0.0
level : int or level name, optional
For MultiIndex, level for which the labels will be removed.
inplace : bool, default False
Expand Down
10 changes: 6 additions & 4 deletions pandas/core/window/rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,8 @@ def __init__(
# GH 32262: It's convention to keep the grouping column in
# groupby.<agg_func>, but unexpected to users in
# groupby.rolling.<agg_func>
obj = obj.drop(columns=self._grouper.names, errors="ignore")
if obj.ndim == 2:
obj = obj.drop(columns=self._grouper.names, errors="ignore")
# GH 15354
if kwargs.get("step") is not None:
raise NotImplementedError("step not implemented for groupby")
Expand Down Expand Up @@ -715,7 +716,7 @@ def _apply(
if key not in self.obj.index.names or key is None
]

if len(drop_columns) != len(groupby_keys):
if len(drop_columns) != len(groupby_keys) and result.ndim == 2:
# Our result will have still kept the column in the result
result = result.drop(columns=drop_columns, errors="ignore")

Expand Down Expand Up @@ -758,8 +759,9 @@ def _apply_pairwise(
"""
Apply the given pairwise function given 2 pandas objects (DataFrame/Series)
"""
# Manually drop the grouping column first
target = target.drop(columns=self._grouper.names, errors="ignore")
if target.ndim == 2:
# Manually drop the grouping column first
target = target.drop(columns=self._grouper.names, errors="ignore")
result = super()._apply_pairwise(target, other, pairwise, func, numeric_only)
# 1) Determine the levels + codes of the groupby levels
if other is not None and not all(
Expand Down
11 changes: 11 additions & 0 deletions pandas/tests/series/methods/test_drop.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import pytest

from pandas.errors import Pandas4Warning

from pandas import (
Index,
Series,
Expand Down Expand Up @@ -97,3 +99,12 @@ def test_drop_index_ea_dtype(any_numeric_ea_dtype):
result = df.drop(idx)
expected = Series(100, index=Index([1], dtype=any_numeric_ea_dtype))
tm.assert_series_equal(result, expected)


def test_drop_series_columns_deprecated():
# GH#39509
ser = Series({"a": 1, "b": 3})

msg = "the 'columns' keyword is deprecated and will be removed"
with tm.assert_produces_warning(Pandas4Warning, match=msg):
ser.drop(columns=["a"])
Loading