Skip to content

Commit 2cb482f

Browse files
committed
ENH: Deprecate non-keyword arguments for drop_duplicates.
1 parent c0d3d34 commit 2cb482f

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

doc/source/whatsnew/v1.3.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ Deprecations
676676
- Deprecated using ``usecols`` with out of bounds indices for ``read_csv`` with ``engine="c"`` (:issue:`25623`)
677677
- Deprecated special treatment of lists with first element a Categorical in the :class:`DataFrame` constructor; pass as ``pd.DataFrame({col: categorical, ...})`` instead (:issue:`38845`)
678678
- Deprecated passing arguments as positional (except for ``"method"``) in :meth:`DataFrame.interpolate` and :meth:`Series.interpolate` (:issue:`41485`)
679-
- Deprecated passing arguments as positional in :meth:`DataFrame.drop_duplicates` (except for ``subset``), :meth:`Series.drop_duplicates` and :meth:`Index.drop_duplicates` (:issue:`41485`)
679+
- Deprecated passing arguments as positional in :meth:`DataFrame.drop_duplicates` (except for ``subset``), :meth:`Series.drop_duplicates`, :meth:`Index.drop_duplicates` and :meth:`MultiIndex.drop_duplicates`(:issue:`41485`)
680680
- Deprecated passing arguments (apart from ``value``) as positional in :meth:`DataFrame.fillna` and :meth:`Series.fillna` (:issue:`41485`)
681681
- Deprecated construction of :class:`Series` or :class:`DataFrame` with ``DatetimeTZDtype`` data and ``datetime64[ns]`` dtype. Use ``Series(data).dt.tz_localize(None)`` instead (:issue:`41555`,:issue:`33401`)
682682

pandas/core/indexes/multi.py

+7
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
from pandas.util._decorators import (
4242
Appender,
4343
cache_readonly,
44+
deprecate_nonkeyword_arguments,
4445
doc,
4546
)
4647

@@ -77,8 +78,10 @@
7778
from pandas.core.indexes.base import (
7879
Index,
7980
_index_shared_docs,
81+
_IndexT,
8082
ensure_index,
8183
get_unanimous_names,
84+
str_t,
8285
)
8386
from pandas.core.indexes.frozen import FrozenList
8487
from pandas.core.indexes.numeric import Int64Index
@@ -3793,6 +3796,10 @@ def isin(self, values, level=None) -> np.ndarray:
37933796
return np.zeros(len(levs), dtype=np.bool_)
37943797
return levs.isin(values)
37953798

3799+
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self"])
3800+
def drop_duplicates(self: _IndexT, keep: str_t | bool = "first") -> _IndexT:
3801+
return super(Index, self).drop_duplicates(keep=keep)
3802+
37963803
# ---------------------------------------------------------------
37973804
# Arithmetic/Numeric Methods - Disabled
37983805

pandas/tests/indexes/multi/test_duplicates.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -309,11 +309,13 @@ def test_duplicated_drop_duplicates():
309309

310310

311311
def test_multi_drop_duplicates_pos_args_deprecation():
312+
# GH#41485
313+
312314
idx = MultiIndex.from_arrays([[1, 2, 3, 1], [1, 2, 3, 1]])
313315

314316
msg = (
315317
"In a future version of pandas all arguments of "
316-
"Index.drop_duplicates will be keyword-only"
318+
"MultiIndex.drop_duplicates will be keyword-only"
317319
)
318320

319321
with tm.assert_produces_warning(FutureWarning, match=msg):

pandas/tests/indexes/test_base.py

+2
Original file line numberDiff line numberDiff line change
@@ -1741,6 +1741,8 @@ def test_construct_from_memoryview(klass, extra_kwargs):
17411741

17421742

17431743
def test_drop_duplicates_pos_args_deprecation():
1744+
# GH#41485
1745+
17441746
idx = Index([1, 2, 3, 1])
17451747

17461748
msg = (

0 commit comments

Comments
 (0)