diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index c352a36bf6de1..cc4bab8b9a923 100644 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -61,7 +61,7 @@ Deprecations Removal of prior version deprecations/changes ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Removed the previously deprecated :meth:`Series.get_value`, :meth:`Series.set_value`, :meth:`DataFrame.get_value`, :meth:`DataFrame.set_value` (:issue:`17739`) -- +- Changed the the default value of `inplace` in :meth:`DataFrame.set_index` and :meth:`Series.set_axis`. It now defaults to False (:issue:`27600`) - .. _whatsnew_1000.performance: @@ -190,7 +190,6 @@ ExtensionArray - - - .. _whatsnew_1000.contributors: Contributors diff --git a/pandas/core/generic.py b/pandas/core/generic.py index b900e1e82255d..97a0b04146297 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -564,7 +564,7 @@ def _obj_with_exclusions(self): """ internal compat with SelectionMixin """ return self - def set_axis(self, labels, axis=0, inplace=None): + def set_axis(self, labels, axis=0, inplace=False): """ Assign desired index to given axis. @@ -587,15 +587,9 @@ def set_axis(self, labels, axis=0, inplace=None): The axis to update. The value 0 identifies the rows, and 1 identifies the columns. - inplace : bool, default None + inplace : bool, default False Whether to return a new %(klass)s instance. - .. warning:: - - ``inplace=None`` currently falls back to to True, but in a - future version, will default to False. Use inplace=True - explicitly rather than relying on the default. - Returns ------- renamed : %(klass)s or None @@ -616,27 +610,19 @@ def set_axis(self, labels, axis=0, inplace=None): 2 3 dtype: int64 - >>> s.set_axis(['a', 'b', 'c'], axis=0, inplace=False) + >>> s.set_axis(['a', 'b', 'c'], axis=0) a 1 b 2 c 3 dtype: int64 - The original object is not modified. - - >>> s - 0 1 - 1 2 - 2 3 - dtype: int64 - **DataFrame** >>> df = pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]}) Change the row labels. - >>> df.set_axis(['a', 'b', 'c'], axis='index', inplace=False) + >>> df.set_axis(['a', 'b', 'c'], axis='index') A B a 1 4 b 2 5 @@ -644,7 +630,7 @@ def set_axis(self, labels, axis=0, inplace=None): Change the column labels. - >>> df.set_axis(['I', 'II'], axis='columns', inplace=False) + >>> df.set_axis(['I', 'II'], axis='columns') I II 0 1 4 1 2 5 @@ -670,15 +656,6 @@ def set_axis(self, labels, axis=0, inplace=None): ) labels, axis = axis, labels - if inplace is None: - warnings.warn( - "set_axis currently defaults to operating inplace.\nThis " - "will change in a future version of pandas, use " - "inplace=True to avoid this warning.", - FutureWarning, - stacklevel=2, - ) - inplace = True if inplace: setattr(self, self._get_axis_name(axis), labels) else: diff --git a/pandas/tests/frame/test_alter_axes.py b/pandas/tests/frame/test_alter_axes.py index c57b2a6964f39..6a274c8369328 100644 --- a/pandas/tests/frame/test_alter_axes.py +++ b/pandas/tests/frame/test_alter_axes.py @@ -1515,30 +1515,23 @@ def test_set_axis_inplace(self): expected["columns"] = expected[1] for axis in expected: - # inplace=True - # The FutureWarning comes from the fact that we would like to have - # inplace default to False some day - for inplace, warn in (None, FutureWarning), (True, None): - kwargs = {"inplace": inplace} - - result = df.copy() - with tm.assert_produces_warning(warn): - result.set_axis(list("abc"), axis=axis, **kwargs) - tm.assert_frame_equal(result, expected[axis]) + result = df.copy() + result.set_axis(list("abc"), axis=axis, inplace=True) + tm.assert_frame_equal(result, expected[axis]) # inplace=False - result = df.set_axis(list("abc"), axis=axis, inplace=False) + result = df.set_axis(list("abc"), axis=axis) tm.assert_frame_equal(expected[axis], result) # omitting the "axis" parameter with tm.assert_produces_warning(None): - result = df.set_axis(list("abc"), inplace=False) + result = df.set_axis(list("abc")) tm.assert_frame_equal(result, expected[0]) # wrong values for the "axis" parameter for axis in 3, "foo": with pytest.raises(ValueError, match="No axis named"): - df.set_axis(list("abc"), axis=axis, inplace=False) + df.set_axis(list("abc"), axis=axis) def test_set_axis_prior_to_deprecation_signature(self): df = DataFrame( diff --git a/pandas/tests/series/test_alter_axes.py b/pandas/tests/series/test_alter_axes.py index 63baa6af7c02a..f58462c0f3576 100644 --- a/pandas/tests/series/test_alter_axes.py +++ b/pandas/tests/series/test_alter_axes.py @@ -277,12 +277,9 @@ def test_set_axis_inplace_axes(self, axis_series): # inplace=True # The FutureWarning comes from the fact that we would like to have # inplace default to False some day - for inplace, warn in [(None, FutureWarning), (True, None)]: - result = ser.copy() - kwargs = {"inplace": inplace} - with tm.assert_produces_warning(warn): - result.set_axis(list("abcd"), axis=axis_series, **kwargs) - tm.assert_series_equal(result, expected) + result = ser.copy() + result.set_axis(list("abcd"), axis=axis_series, inplace=True) + tm.assert_series_equal(result, expected) def test_set_axis_inplace(self): # GH14636