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 23, 2021
1 parent c0d3d34 commit 2cb482f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v1.3.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ Deprecations
- Deprecated using ``usecols`` with out of bounds indices for ``read_csv`` with ``engine="c"`` (:issue:`25623`)
- Deprecated special treatment of lists with first element a Categorical in the :class:`DataFrame` constructor; pass as ``pd.DataFrame({col: categorical, ...})`` instead (:issue:`38845`)
- Deprecated passing arguments as positional (except for ``"method"``) in :meth:`DataFrame.interpolate` and :meth:`Series.interpolate` (:issue:`41485`)
- Deprecated passing arguments as positional in :meth:`DataFrame.drop_duplicates` (except for ``subset``), :meth:`Series.drop_duplicates` and :meth:`Index.drop_duplicates` (:issue:`41485`)
- 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`)
- Deprecated passing arguments (apart from ``value``) as positional in :meth:`DataFrame.fillna` and :meth:`Series.fillna` (:issue:`41485`)
- 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`)

Expand Down
7 changes: 7 additions & 0 deletions pandas/core/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
from pandas.util._decorators import (
Appender,
cache_readonly,
deprecate_nonkeyword_arguments,
doc,
)

Expand Down Expand Up @@ -77,8 +78,10 @@
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 @@ -3793,6 +3796,10 @@ def isin(self, values, level=None) -> np.ndarray:
return np.zeros(len(levs), dtype=np.bool_)
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)

# ---------------------------------------------------------------
# Arithmetic/Numeric Methods - Disabled

Expand Down
4 changes: 3 additions & 1 deletion pandas/tests/indexes/multi/test_duplicates.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,11 +309,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 "
"Index.drop_duplicates will be keyword-only"
"MultiIndex.drop_duplicates will be keyword-only"
)

with tm.assert_produces_warning(FutureWarning, match=msg):
Expand Down
2 changes: 2 additions & 0 deletions pandas/tests/indexes/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1741,6 +1741,8 @@ def test_construct_from_memoryview(klass, extra_kwargs):


def test_drop_duplicates_pos_args_deprecation():
# GH#41485

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

msg = (
Expand Down

0 comments on commit 2cb482f

Please sign in to comment.