Skip to content

Commit 887e484

Browse files
pilkibunquintusdias
pilkibun
authored andcommitted
DEPR: NDFrame.set_axis inplace defaults to false pandas-dev#27525 (pandas-dev#27600)
1 parent 204b7e3 commit 887e484

File tree

4 files changed

+15
-49
lines changed

4 files changed

+15
-49
lines changed

doc/source/whatsnew/v1.0.0.rst

+1-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Deprecations
6161
Removal of prior version deprecations/changes
6262
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6363
- Removed the previously deprecated :meth:`Series.get_value`, :meth:`Series.set_value`, :meth:`DataFrame.get_value`, :meth:`DataFrame.set_value` (:issue:`17739`)
64-
-
64+
- Changed the the default value of `inplace` in :meth:`DataFrame.set_index` and :meth:`Series.set_axis`. It now defaults to False (:issue:`27600`)
6565
-
6666

6767
.. _whatsnew_1000.performance:
@@ -190,7 +190,6 @@ ExtensionArray
190190
-
191191
-
192192

193-
194193
.. _whatsnew_1000.contributors:
195194

196195
Contributors

pandas/core/generic.py

+5-28
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ def _obj_with_exclusions(self):
564564
""" internal compat with SelectionMixin """
565565
return self
566566

567-
def set_axis(self, labels, axis=0, inplace=None):
567+
def set_axis(self, labels, axis=0, inplace=False):
568568
"""
569569
Assign desired index to given axis.
570570
@@ -587,15 +587,9 @@ def set_axis(self, labels, axis=0, inplace=None):
587587
The axis to update. The value 0 identifies the rows, and 1
588588
identifies the columns.
589589
590-
inplace : bool, default None
590+
inplace : bool, default False
591591
Whether to return a new %(klass)s instance.
592592
593-
.. warning::
594-
595-
``inplace=None`` currently falls back to to True, but in a
596-
future version, will default to False. Use inplace=True
597-
explicitly rather than relying on the default.
598-
599593
Returns
600594
-------
601595
renamed : %(klass)s or None
@@ -616,35 +610,27 @@ def set_axis(self, labels, axis=0, inplace=None):
616610
2 3
617611
dtype: int64
618612
619-
>>> s.set_axis(['a', 'b', 'c'], axis=0, inplace=False)
613+
>>> s.set_axis(['a', 'b', 'c'], axis=0)
620614
a 1
621615
b 2
622616
c 3
623617
dtype: int64
624618
625-
The original object is not modified.
626-
627-
>>> s
628-
0 1
629-
1 2
630-
2 3
631-
dtype: int64
632-
633619
**DataFrame**
634620
635621
>>> df = pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]})
636622
637623
Change the row labels.
638624
639-
>>> df.set_axis(['a', 'b', 'c'], axis='index', inplace=False)
625+
>>> df.set_axis(['a', 'b', 'c'], axis='index')
640626
A B
641627
a 1 4
642628
b 2 5
643629
c 3 6
644630
645631
Change the column labels.
646632
647-
>>> df.set_axis(['I', 'II'], axis='columns', inplace=False)
633+
>>> df.set_axis(['I', 'II'], axis='columns')
648634
I II
649635
0 1 4
650636
1 2 5
@@ -670,15 +656,6 @@ def set_axis(self, labels, axis=0, inplace=None):
670656
)
671657
labels, axis = axis, labels
672658

673-
if inplace is None:
674-
warnings.warn(
675-
"set_axis currently defaults to operating inplace.\nThis "
676-
"will change in a future version of pandas, use "
677-
"inplace=True to avoid this warning.",
678-
FutureWarning,
679-
stacklevel=2,
680-
)
681-
inplace = True
682659
if inplace:
683660
setattr(self, self._get_axis_name(axis), labels)
684661
else:

pandas/tests/frame/test_alter_axes.py

+6-13
Original file line numberDiff line numberDiff line change
@@ -1515,30 +1515,23 @@ def test_set_axis_inplace(self):
15151515
expected["columns"] = expected[1]
15161516

15171517
for axis in expected:
1518-
# inplace=True
1519-
# The FutureWarning comes from the fact that we would like to have
1520-
# inplace default to False some day
1521-
for inplace, warn in (None, FutureWarning), (True, None):
1522-
kwargs = {"inplace": inplace}
1523-
1524-
result = df.copy()
1525-
with tm.assert_produces_warning(warn):
1526-
result.set_axis(list("abc"), axis=axis, **kwargs)
1527-
tm.assert_frame_equal(result, expected[axis])
1518+
result = df.copy()
1519+
result.set_axis(list("abc"), axis=axis, inplace=True)
1520+
tm.assert_frame_equal(result, expected[axis])
15281521

15291522
# inplace=False
1530-
result = df.set_axis(list("abc"), axis=axis, inplace=False)
1523+
result = df.set_axis(list("abc"), axis=axis)
15311524
tm.assert_frame_equal(expected[axis], result)
15321525

15331526
# omitting the "axis" parameter
15341527
with tm.assert_produces_warning(None):
1535-
result = df.set_axis(list("abc"), inplace=False)
1528+
result = df.set_axis(list("abc"))
15361529
tm.assert_frame_equal(result, expected[0])
15371530

15381531
# wrong values for the "axis" parameter
15391532
for axis in 3, "foo":
15401533
with pytest.raises(ValueError, match="No axis named"):
1541-
df.set_axis(list("abc"), axis=axis, inplace=False)
1534+
df.set_axis(list("abc"), axis=axis)
15421535

15431536
def test_set_axis_prior_to_deprecation_signature(self):
15441537
df = DataFrame(

pandas/tests/series/test_alter_axes.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -277,12 +277,9 @@ def test_set_axis_inplace_axes(self, axis_series):
277277
# inplace=True
278278
# The FutureWarning comes from the fact that we would like to have
279279
# inplace default to False some day
280-
for inplace, warn in [(None, FutureWarning), (True, None)]:
281-
result = ser.copy()
282-
kwargs = {"inplace": inplace}
283-
with tm.assert_produces_warning(warn):
284-
result.set_axis(list("abcd"), axis=axis_series, **kwargs)
285-
tm.assert_series_equal(result, expected)
280+
result = ser.copy()
281+
result.set_axis(list("abcd"), axis=axis_series, inplace=True)
282+
tm.assert_series_equal(result, expected)
286283

287284
def test_set_axis_inplace(self):
288285
# GH14636

0 commit comments

Comments
 (0)