Skip to content

Commit fbf70a2

Browse files
committed
ENH: Deprecate non-keyword arguments for drop_duplicates.
1 parent 09fe413 commit fbf70a2

File tree

5 files changed

+2
-22
lines changed

5 files changed

+2
-22
lines changed

pandas/core/indexes/multi.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,8 @@
7878
from pandas.core.indexes.base import (
7979
Index,
8080
_index_shared_docs,
81-
_IndexT,
8281
ensure_index,
8382
get_unanimous_names,
84-
str_t,
8583
)
8684
from pandas.core.indexes.frozen import FrozenList
8785
from pandas.core.indexes.numeric import Int64Index
@@ -3797,8 +3795,8 @@ def isin(self, values, level=None) -> np.ndarray:
37973795
return levs.isin(values)
37983796

37993797
@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)
3798+
def drop_duplicates(self, keep: str | bool = "first") -> MultiIndex:
3799+
return super().drop_duplicates(keep=keep)
38023800

38033801
# ---------------------------------------------------------------
38043802
# Arithmetic/Numeric Methods - Disabled

pandas/tests/frame/methods/test_drop_duplicates.py

-4
Original file line numberDiff line numberDiff line change
@@ -476,16 +476,12 @@ def test_drop_duplicates_non_boolean_ignore_index(arg):
476476
def test_drop_duplicates_pos_args_deprecation():
477477
# GH#41485
478478
df = DataFrame({"a": [1, 1, 2], "b": [1, 1, 3], "c": [1, 1, 3]})
479-
480479
msg = (
481480
"In a future version of pandas all arguments of "
482481
"DataFrame.drop_duplicates except for the argument 'subset' "
483482
"will be keyword-only"
484483
)
485-
486484
with tm.assert_produces_warning(FutureWarning, match=msg):
487485
result = df.drop_duplicates(["b", "c"], "last")
488-
489486
expected = DataFrame({"a": [1, 2], "b": [1, 3], "c": [1, 3]}, index=[1, 2])
490-
491487
tm.assert_frame_equal(expected, result)

pandas/tests/indexes/multi/test_duplicates.py

-5
Original file line numberDiff line numberDiff line change
@@ -310,18 +310,13 @@ def test_duplicated_drop_duplicates():
310310

311311
def test_multi_drop_duplicates_pos_args_deprecation():
312312
# GH#41485
313-
314313
idx = MultiIndex.from_arrays([[1, 2, 3, 1], [1, 2, 3, 1]])
315-
316314
msg = (
317315
"In a future version of pandas all arguments of "
318316
"MultiIndex.drop_duplicates will be keyword-only"
319317
)
320-
321318
with tm.assert_produces_warning(FutureWarning, match=msg):
322319
idx.drop_duplicates("last")
323320
result = idx.drop_duplicates("last")
324-
325321
expected = MultiIndex.from_arrays([[2, 3, 1], [2, 3, 1]])
326-
327322
tm.assert_index_equal(expected, result)

pandas/tests/indexes/test_base.py

-5
Original file line numberDiff line numberDiff line change
@@ -1742,18 +1742,13 @@ def test_construct_from_memoryview(klass, extra_kwargs):
17421742

17431743
def test_drop_duplicates_pos_args_deprecation():
17441744
# GH#41485
1745-
17461745
idx = Index([1, 2, 3, 1])
1747-
17481746
msg = (
17491747
"In a future version of pandas all arguments of "
17501748
"Index.drop_duplicates will be keyword-only"
17511749
)
1752-
17531750
with tm.assert_produces_warning(FutureWarning, match=msg):
17541751
idx.drop_duplicates("last")
17551752
result = idx.drop_duplicates("last")
1756-
17571753
expected = Index([2, 3, 1])
1758-
17591754
tm.assert_index_equal(expected, result)

pandas/tests/series/methods/test_drop_duplicates.py

-4
Original file line numberDiff line numberDiff line change
@@ -228,15 +228,11 @@ def test_drop_duplicates_categorical_bool(self, ordered):
228228
def test_drop_duplicates_pos_args_deprecation():
229229
# GH#41485
230230
s = Series(["a", "b", "c", "b"])
231-
232231
msg = (
233232
"In a future version of pandas all arguments of "
234233
"Series.drop_duplicates will be keyword-only"
235234
)
236-
237235
with tm.assert_produces_warning(FutureWarning, match=msg):
238236
result = s.drop_duplicates("last")
239-
240237
expected = Series(["a", "c", "b"], index=[0, 2, 3])
241-
242238
tm.assert_series_equal(expected, result)

0 commit comments

Comments
 (0)