Skip to content

Commit 94a39df

Browse files
PydareTLouf
authored andcommitted
Deprecated nonkeyword arguments for set_codes function (pandas-dev#41650)
1 parent 281dcc3 commit 94a39df

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

doc/source/whatsnew/v1.3.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,7 @@ Deprecations
679679
- Deprecated the ``convert_float`` optional argument in :func:`read_excel` and :meth:`ExcelFile.parse` (:issue:`41127`)
680680
- 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`)
681681
- Deprecated using ``usecols`` with out of bounds indices for ``read_csv`` with ``engine="c"`` (:issue:`25623`)
682+
- Deprecated passing arguments as positional (except for ``"codes"``) in :meth:`MultiIndex.codes` (:issue:`41485`)
682683
- Deprecated passing arguments as positional in :meth:`Index.set_names` and :meth:`MultiIndex.set_names` (except for ``names``) (:issue:`41485`)
683684
- Deprecated passing arguments (apart from ``cond`` and ``other``) as positional in :meth:`DataFrame.mask` and :meth:`Series.mask` (:issue:`41485`)
684685
- Deprecated passing arguments as positional in :meth:`DataFrame.clip` and :meth:`Series.clip` (other than ``"upper"`` and ``"lower"``) (:issue:`41485`)

pandas/core/indexes/multi.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,7 @@ def _set_codes(
991991

992992
self._reset_cache()
993993

994+
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "codes"])
994995
def set_codes(self, codes, level=None, inplace=None, verify_integrity: bool = True):
995996
"""
996997
Set new codes on MultiIndex. Defaults to returning new index.
@@ -1058,7 +1059,7 @@ def set_codes(self, codes, level=None, inplace=None, verify_integrity: bool = Tr
10581059
warnings.warn(
10591060
"inplace is deprecated and will be removed in a future version.",
10601061
FutureWarning,
1061-
stacklevel=2,
1062+
stacklevel=3,
10621063
)
10631064
else:
10641065
inplace = False

pandas/tests/indexes/multi/test_get_set.py

+22
Original file line numberDiff line numberDiff line change
@@ -449,3 +449,25 @@ def test_set_levels_pos_args_deprecation():
449449
names=["foo", "bar"],
450450
)
451451
tm.assert_index_equal(result, expected)
452+
453+
454+
def test_set_codes_pos_args_depreciation(idx):
455+
# https://github.com/pandas-dev/pandas/issues/41485
456+
msg = (
457+
r"In a future version of pandas all arguments of MultiIndex.set_codes except "
458+
r"for the argument 'codes' will be keyword-only"
459+
)
460+
with tm.assert_produces_warning(FutureWarning, match=msg):
461+
result = idx.set_codes([[0, 0, 1, 2, 3, 3], [0, 1, 0, 1, 0, 1]], [0, 1])
462+
expected = MultiIndex.from_tuples(
463+
[
464+
("foo", "one"),
465+
("foo", "two"),
466+
("bar", "one"),
467+
("baz", "two"),
468+
("qux", "one"),
469+
("qux", "two"),
470+
],
471+
names=["first", "second"],
472+
)
473+
tm.assert_index_equal(result, expected)

0 commit comments

Comments
 (0)