Skip to content

Commit 24cd863

Browse files
MarcoGorelliJulianWgs
authored andcommitted
Deprecate passing default args as positional in DataFrame.set_index (pandas-dev#41495)
1 parent 18d2f14 commit 24cd863

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

doc/source/whatsnew/v1.3.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,7 @@ Deprecations
682682
- Deprecated passing arguments as positional in :meth:`DataFrame.clip` and :meth:`Series.clip` (other than ``"upper"`` and ``"lower"``) (:issue:`41485`)
683683
- Deprecated special treatment of lists with first element a Categorical in the :class:`DataFrame` constructor; pass as ``pd.DataFrame({col: categorical, ...})`` instead (:issue:`38845`)
684684
- Deprecated passing arguments as positional (except for ``"method"``) in :meth:`DataFrame.interpolate` and :meth:`Series.interpolate` (:issue:`41485`)
685+
- Deprecated passing arguments as positional in :meth:`DataFrame.set_index` (other than ``"keys"``) (:issue:`41485`)
685686
- Deprecated passing arguments as positional (except for ``"levels"``) in :meth:`MultiIndex.set_levels` (:issue:`41485`)
686687
- Deprecated passing arguments as positional in :meth:`DataFrame.sort_index` and :meth:`Series.sort_index` (:issue:`41485`)
687688
- 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`)

pandas/core/frame.py

+1
Original file line numberDiff line numberDiff line change
@@ -5330,6 +5330,7 @@ def shift(
53305330
periods=periods, freq=freq, axis=axis, fill_value=fill_value
53315331
)
53325332

5333+
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "keys"])
53335334
def set_index(
53345335
self,
53355336
keys,

pandas/tests/frame/methods/test_set_index.py

+12
Original file line numberDiff line numberDiff line change
@@ -704,3 +704,15 @@ def test_set_index_periodindex(self):
704704
tm.assert_index_equal(df.index, idx1)
705705
df = df.set_index(idx2)
706706
tm.assert_index_equal(df.index, idx2)
707+
708+
def test_drop_pos_args_deprecation(self):
709+
# https://github.com/pandas-dev/pandas/issues/41485
710+
df = DataFrame({"a": [1, 2, 3]})
711+
msg = (
712+
r"In a future version of pandas all arguments of DataFrame\.set_index "
713+
r"except for the argument 'keys' will be keyword-only"
714+
)
715+
with tm.assert_produces_warning(FutureWarning, match=msg):
716+
result = df.set_index("a", True)
717+
expected = DataFrame(index=Index([1, 2, 3], name="a"))
718+
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)