Skip to content

Commit

Permalink
ENH: Deprecate non-keyword arguments for drop_duplicates.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmholzer committed May 24, 2021
1 parent 09fe413 commit fbf70a2
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 22 deletions.
6 changes: 2 additions & 4 deletions pandas/core/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,8 @@
from pandas.core.indexes.base import (
Index,
_index_shared_docs,
_IndexT,
ensure_index,
get_unanimous_names,
str_t,
)
from pandas.core.indexes.frozen import FrozenList
from pandas.core.indexes.numeric import Int64Index
Expand Down Expand Up @@ -3797,8 +3795,8 @@ def isin(self, values, level=None) -> np.ndarray:
return levs.isin(values)

@deprecate_nonkeyword_arguments(version=None, allowed_args=["self"])
def drop_duplicates(self: _IndexT, keep: str_t | bool = "first") -> _IndexT:
return super(Index, self).drop_duplicates(keep=keep)
def drop_duplicates(self, keep: str | bool = "first") -> MultiIndex:
return super().drop_duplicates(keep=keep)

# ---------------------------------------------------------------
# Arithmetic/Numeric Methods - Disabled
Expand Down
4 changes: 0 additions & 4 deletions pandas/tests/frame/methods/test_drop_duplicates.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,16 +476,12 @@ def test_drop_duplicates_non_boolean_ignore_index(arg):
def test_drop_duplicates_pos_args_deprecation():
# GH#41485
df = DataFrame({"a": [1, 1, 2], "b": [1, 1, 3], "c": [1, 1, 3]})

msg = (
"In a future version of pandas all arguments of "
"DataFrame.drop_duplicates except for the argument 'subset' "
"will be keyword-only"
)

with tm.assert_produces_warning(FutureWarning, match=msg):
result = df.drop_duplicates(["b", "c"], "last")

expected = DataFrame({"a": [1, 2], "b": [1, 3], "c": [1, 3]}, index=[1, 2])

tm.assert_frame_equal(expected, result)
5 changes: 0 additions & 5 deletions pandas/tests/indexes/multi/test_duplicates.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,18 +310,13 @@ def test_duplicated_drop_duplicates():

def test_multi_drop_duplicates_pos_args_deprecation():
# GH#41485

idx = MultiIndex.from_arrays([[1, 2, 3, 1], [1, 2, 3, 1]])

msg = (
"In a future version of pandas all arguments of "
"MultiIndex.drop_duplicates will be keyword-only"
)

with tm.assert_produces_warning(FutureWarning, match=msg):
idx.drop_duplicates("last")
result = idx.drop_duplicates("last")

expected = MultiIndex.from_arrays([[2, 3, 1], [2, 3, 1]])

tm.assert_index_equal(expected, result)
5 changes: 0 additions & 5 deletions pandas/tests/indexes/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1742,18 +1742,13 @@ def test_construct_from_memoryview(klass, extra_kwargs):

def test_drop_duplicates_pos_args_deprecation():
# GH#41485

idx = Index([1, 2, 3, 1])

msg = (
"In a future version of pandas all arguments of "
"Index.drop_duplicates will be keyword-only"
)

with tm.assert_produces_warning(FutureWarning, match=msg):
idx.drop_duplicates("last")
result = idx.drop_duplicates("last")

expected = Index([2, 3, 1])

tm.assert_index_equal(expected, result)
4 changes: 0 additions & 4 deletions pandas/tests/series/methods/test_drop_duplicates.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,15 +228,11 @@ def test_drop_duplicates_categorical_bool(self, ordered):
def test_drop_duplicates_pos_args_deprecation():
# GH#41485
s = Series(["a", "b", "c", "b"])

msg = (
"In a future version of pandas all arguments of "
"Series.drop_duplicates will be keyword-only"
)

with tm.assert_produces_warning(FutureWarning, match=msg):
result = s.drop_duplicates("last")

expected = Series(["a", "c", "b"], index=[0, 2, 3])

tm.assert_series_equal(expected, result)

0 comments on commit fbf70a2

Please sign in to comment.