Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.3.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,7 @@ Deprecations
- Deprecated setting :attr:`Categorical._codes`, create a new :class:`Categorical` with the desired codes instead (:issue:`40606`)
- Deprecated behavior of :meth:`DatetimeIndex.union` with mixed timezones; in a future version both will be cast to UTC instead of object dtype (:issue:`39328`)
- Deprecated using ``usecols`` with out of bounds indices for ``read_csv`` with ``engine="c"`` (:issue:`25623`)
- Deprecated passing arguments as positional (except for ``"codes"``) in :meth:`MultiIndex.codes` (:issue:`41485`)
- 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 (apart from ``value``) as positional in :meth:`DataFrame.fillna` and :meth:`Series.fillna` (:issue:`41485`)
Expand Down
4 changes: 3 additions & 1 deletion 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 @@ -994,6 +995,7 @@ def _set_codes(

self._reset_cache()

@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "codes"])
def set_codes(self, codes, level=None, inplace=None, verify_integrity: bool = True):
"""
Set new codes on MultiIndex. Defaults to returning new index.
Expand Down Expand Up @@ -1061,7 +1063,7 @@ def set_codes(self, codes, level=None, inplace=None, verify_integrity: bool = Tr
warnings.warn(
"inplace is deprecated and will be removed in a future version.",
FutureWarning,
stacklevel=2,
stacklevel=3,
)
else:
inplace = False
Expand Down
29 changes: 29 additions & 0 deletions pandas/tests/indexes/multi/test_get_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,3 +405,32 @@ def test_set_levels_inplace_deprecated(idx, inplace):

with tm.assert_produces_warning(FutureWarning):
idx.set_levels(levels=new_level, level=1, inplace=inplace)


def test_set_codes_pos_args_depreciation():
# https://github.com/pandas-dev/pandas/issues/41485
idx = MultiIndex.from_tuples(
[
(1, "one"),
(1, "two"),
(2, "one"),
(2, "two"),
],
names=["foo", "bar"]
)
msg = (
r"In a future version of pandas all arguments of MultiIndex.set_codes except"
r"for the argument 'codes' will be keyword-only"
)
with tm.assert_produces_warning(FutureWarning, match=msg):
result = idx.set_codes([[1, 0, 1, 0], [0, 0, 1, 1]])
expected = MultiIndex.from_tuples(
[
(2, "one"),
(1, "one"),
(2, "two"),
(1, "two"),
],
names=["foo", "bar"]
)
tm.assert_index_equal(result, expected)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lint issue