Skip to content

Commit 17f5ff0

Browse files
committed
ENH: Deprecate non-keyword arguments for Index.set_names.
1 parent f6e9ac1 commit 17f5ff0

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

pandas/core/indexes/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1527,7 +1527,7 @@ def _set_names(self, values, level=None) -> None:
15271527

15281528
names = property(fset=_set_names, fget=_get_names)
15291529

1530-
@deprecate_nonkeyword_arguments(version="2.0", allowed_args=["self", "names"])
1530+
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "names"])
15311531
@final
15321532
def set_names(self, names, level=None, inplace: bool = False):
15331533
"""

pandas/tests/indexes/multi/test_get_set.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -350,12 +350,20 @@ def test_multi_set_names_pos_args_deprecation():
350350
idx = MultiIndex.from_product([["python", "cobra"], [2018, 2019]])
351351

352352
msg = (
353-
"Starting with pandas version 2.0 all arguments of Index.set_names "
353+
"In a future version of pandas all arguments of Index.set_names "
354354
"except for the argument 'names' will be keyword-only"
355355
)
356356

357357
with tm.assert_produces_warning(FutureWarning, match=msg):
358-
idx.set_names(["kind", "year"], None)
358+
result = idx.set_names(["kind", "year"], None)
359+
360+
expected = MultiIndex(
361+
levels=[["python", "cobra"], [2018, 2019]],
362+
codes=[[0, 0, 1, 1], [0, 1, 0, 1]],
363+
names=["kind", "year"],
364+
)
365+
366+
tm.assert_index_equal(result, expected)
359367

360368

361369
@pytest.mark.parametrize("ordered", [True, False])

pandas/tests/indexes/test_base.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -1745,9 +1745,13 @@ def test_index_set_names_pos_args_deprecation():
17451745
idx = Index([1, 2, 3, 4])
17461746

17471747
msg = (
1748-
"Starting with pandas version 2.0 all arguments of Index.set_names "
1748+
"In a future version of pandas all arguments of Index.set_names "
17491749
"except for the argument 'names' will be keyword-only"
17501750
)
17511751

17521752
with tm.assert_produces_warning(FutureWarning, match=msg):
1753-
idx.set_names("quarter", None)
1753+
result = idx.set_names("quarter", None)
1754+
1755+
expected = Index([1, 2, 3, 4], name="quarter")
1756+
1757+
tm.assert_index_equal(result, expected)

0 commit comments

Comments
 (0)