Skip to content

Commit 56a8abe

Browse files
committed
ENH: Deprecate non-keyword arguments for drop_duplicates.
1 parent 3ea8b3b commit 56a8abe

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

pandas/core/frame.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6005,7 +6005,7 @@ def dropna(
60056005
else:
60066006
return result
60076007

6008-
@deprecate_nonkeyword_arguments(version="2.0", allowed_args=["self", "subset"])
6008+
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "subset"])
60096009
def drop_duplicates(
60106010
self,
60116011
subset: Hashable | Sequence[Hashable] | None = None,

pandas/core/series.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2057,7 +2057,7 @@ def drop_duplicates(self, *, inplace: Literal[True]) -> None:
20572057
def drop_duplicates(self, keep=..., inplace: bool = ...) -> Series | None:
20582058
...
20592059

2060-
@deprecate_nonkeyword_arguments(version="2.0", allowed_args=["self"])
2060+
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self"])
20612061
def drop_duplicates(self, keep="first", inplace=False) -> Series | None:
20622062
"""
20632063
Return Series with duplicate values removed.

pandas/tests/frame/methods/test_drop_duplicates.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -476,9 +476,16 @@ 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+
479480
msg = (
480-
r"Starting with Pandas version 2\.0 all arguments of drop_duplicates "
481-
r"except for the arguments 'self' and 'subset' will be keyword-only"
481+
"In a future version of pandas all arguments of "
482+
"DataFrame.drop_duplicates except for the argument 'subset' "
483+
"will be keyword-only"
482484
)
485+
483486
with tm.assert_produces_warning(FutureWarning, match=msg):
484-
df.drop_duplicates(["b", "c"], "last")
487+
result = df.drop_duplicates(["b", "c"], "last")
488+
489+
expected = DataFrame({"a": [1, 2], "b": [1, 3], "c": [1, 3]}, index=[1, 2])
490+
491+
tm.assert_frame_equal(expected, result)

pandas/tests/series/methods/test_drop_duplicates.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,15 @@ 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+
231232
msg = (
232-
r"Starting with Pandas version 2\.0 all arguments of drop_duplicates "
233-
r"except for the argument 'self' will be keyword-only"
233+
"In a future version of pandas all arguments of "
234+
"Series.drop_duplicates will be keyword-only"
234235
)
236+
235237
with tm.assert_produces_warning(FutureWarning, match=msg):
236-
s.drop_duplicates("last")
238+
result = s.drop_duplicates("last")
239+
240+
expected = Series(["a", "c", "b"], index=[0, 2, 3])
241+
242+
tm.assert_series_equal(expected, result)

0 commit comments

Comments
 (0)