From 615dab851c076dcd7fa52f9fe88ce0ff257c4527 Mon Sep 17 00:00:00 2001 From: pilkibun Date: Mon, 22 Jul 2019 14:38:20 -0500 Subject: [PATCH 1/5] DEPR: NDFrame.set_axis inplace defaults to false --- doc/source/whatsnew/v1.0.0.rst | 6 ++++- pandas/core/generic.py | 33 +++++--------------------- pandas/tests/frame/test_alter_axes.py | 19 +++++---------- pandas/tests/series/test_alter_axes.py | 9 +++---- 4 files changed, 20 insertions(+), 47 deletions(-) diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index c352a36bf6de1..4bb01cb606c22 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 of :meth:`DataFrame.set_index` and :meth:`Series.set_index`. It now defaults to False (:issue:``) - .. _whatsnew_1000.performance: @@ -191,6 +191,10 @@ ExtensionArray - +Other +^^^^^ + + .. _whatsnew_1000.contributors: Contributors diff --git a/pandas/core/generic.py b/pandas/core/generic.py index b900e1e82255d..90a88db2d0647 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 @@ -671,14 +657,7 @@ 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 + raise ValueError("`inplace` cannot have None as a value.") 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 From f495777b560f2d97e00336511298b16361170b44 Mon Sep 17 00:00:00 2001 From: pilkibun Date: Thu, 25 Jul 2019 19:21:15 -0500 Subject: [PATCH 2/5] doc --- doc/source/whatsnew/v1.0.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index 4bb01cb606c22..b66425ef1b45a 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 of :meth:`DataFrame.set_index` and :meth:`Series.set_index`. It now defaults to False (:issue:``) +- Changed the the default value of `inplace` in :meth:`DataFrame.set_index` and :meth:`Series.set_axis`. It now defaults to False (:issue:``) - .. _whatsnew_1000.performance: From 0e103c9e70de586b5bc2cbc3c4c1d577b0c7e21d Mon Sep 17 00:00:00 2001 From: pilkibun Date: Thu, 25 Jul 2019 19:22:26 -0500 Subject: [PATCH 3/5] Delete --- pandas/core/generic.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 90a88db2d0647..97a0b04146297 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -656,8 +656,6 @@ def set_axis(self, labels, axis=0, inplace=False): ) labels, axis = axis, labels - if inplace is None: - raise ValueError("`inplace` cannot have None as a value.") if inplace: setattr(self, self._get_axis_name(axis), labels) else: From 2195e3ae7cd21f4bc84157e5db7e33759f681b68 Mon Sep 17 00:00:00 2001 From: pilkibun Date: Thu, 25 Jul 2019 19:46:52 -0500 Subject: [PATCH 4/5] Add missing issue number --- doc/source/whatsnew/v1.0.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index b66425ef1b45a..f9188252e7e3b 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:``) +- 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: From be89e6304328625eedda708c8da85d9320fa519d Mon Sep 17 00:00:00 2001 From: pilkibun Date: Thu, 25 Jul 2019 19:47:16 -0500 Subject: [PATCH 5/5] delete Other --- doc/source/whatsnew/v1.0.0.rst | 5 ----- 1 file changed, 5 deletions(-) diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index f9188252e7e3b..cc4bab8b9a923 100644 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -190,11 +190,6 @@ ExtensionArray - - - -Other -^^^^^ - - .. _whatsnew_1000.contributors: Contributors