Skip to content

Commit 0d54ca7

Browse files
committed
ENH: Deprecate non-keyword arguments for drop_duplicates.
1 parent 448e8a1 commit 0d54ca7

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

pandas/core/frame.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6004,7 +6004,7 @@ def dropna(
60046004
else:
60056005
return result
60066006

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

pandas/core/series.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2025,7 +2025,7 @@ def drop_duplicates(self, *, inplace: Literal[True]) -> None:
20252025
def drop_duplicates(self, keep=..., inplace: bool = ...) -> Series | None:
20262026
...
20272027

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

pandas/tests/frame/methods/test_drop_duplicates.py

Lines changed: 10 additions & 3 deletions
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

Lines changed: 9 additions & 3 deletions
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)