Skip to content

Commit f90896e

Browse files
committed
deprecate default args as positional in set_index
1 parent 4048227 commit f90896e

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

doc/source/whatsnew/v1.3.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,7 @@ Deprecations
647647
- Deprecated setting :attr:`Categorical._codes`, create a new :class:`Categorical` with the desired codes instead (:issue:`40606`)
648648
- 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`)
649649
- Deprecated using ``usecols`` with out of bounds indices for ``read_csv`` with ``engine="c"`` (:issue:`25623`)
650+
- Deprecated passing arguments (apart from ``keys``) as positional in :meth:`DataFrame.set_index` (:issue:`41485`)
650651

651652
.. ---------------------------------------------------------------------------
652653

pandas/core/frame.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
Appender,
7878
Substitution,
7979
deprecate_kwarg,
80+
deprecate_nonkeyword_arguments,
8081
doc,
8182
rewrite_axis_style_signature,
8283
)
@@ -5301,6 +5302,7 @@ def shift(
53015302
periods=periods, freq=freq, axis=axis, fill_value=fill_value
53025303
)
53035304

5305+
@deprecate_nonkeyword_arguments(version="2.0", allowed_args=["self", "keys"])
53045306
def set_index(
53055307
self,
53065308
keys,

pandas/tests/frame/methods/test_set_index.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,3 +705,13 @@ def test_set_index_periodindex(self):
705705
tm.assert_index_equal(df.index, idx1)
706706
df = df.set_index(idx2)
707707
tm.assert_index_equal(df.index, idx2)
708+
709+
def test_drop_pos_args_deprecation(self):
710+
# https://github.com/pandas-dev/pandas/issues/41485
711+
df = DataFrame({"a": [1, 2, 3]})
712+
msg = (
713+
r"Starting with Pandas version 2\.0 all arguments of set_index except for "
714+
r"the arguments 'self' and 'keys' will be keyword-only"
715+
)
716+
with tm.assert_produces_warning(FutureWarning, match=msg):
717+
df.set_index("a", True)

0 commit comments

Comments
 (0)