From 8a968650a1321415677e6e1a8b5a6a4c541cd437 Mon Sep 17 00:00:00 2001 From: pilkibun Date: Mon, 22 Jul 2019 14:38:20 -0500 Subject: [PATCH 1/9] DEPR: NDFrame.set_axis inplace defaults to false --- doc/source/whatsnew/v1.0.0.rst | 2 +- pandas/core/generic.py | 10 ++-------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index 87d3e47cbefe5..2aa1dcc944fce 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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- +- 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: diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 0afd42e406c1f..a36c97382202a 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -565,7 +565,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. @@ -588,15 +588,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 From 3109d0a08cb47b2f3050bc3f80162e2b9db34f01 Mon Sep 17 00:00:00 2001 From: pilkibun Date: Mon, 22 Jul 2019 15:24:39 -0500 Subject: [PATCH 2/9] docstring --- pandas/core/generic.py | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index a36c97382202a..5fd30d9372eb0 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -611,27 +611,19 @@ def set_axis(self, labels, axis=0, inplace=False): 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 @@ -639,7 +631,7 @@ def set_axis(self, labels, axis=0, inplace=False): 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 From 9ccb42a3ef33dc8bbe670b11b619c67822520b1f Mon Sep 17 00:00:00 2001 From: pilkibun Date: Mon, 22 Jul 2019 15:32:31 -0500 Subject: [PATCH 3/9] whatsnew --- 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 2aa1dcc944fce..2a2a4c78d0bc2 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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- 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 of :meth:`DataFrame.set_index` and :meth:`Series.set_index`. It now defaults to False (:issue:`27525`) - .. _whatsnew_1000.performance: From 7dbed266b6876f7fd367b8009bcd5f823e9deede Mon Sep 17 00:00:00 2001 From: pilkibun Date: Mon, 22 Jul 2019 15:33:50 -0500 Subject: [PATCH 4/9] remove warning code --- pandas/core/generic.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 5fd30d9372eb0..6c63a704014db 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -657,15 +657,6 @@ def set_axis(self, labels, axis=0, inplace=False): ) 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: From fd27b8dbd306ad182779d6442c34eaa4da8d2246 Mon Sep 17 00:00:00 2001 From: pilkibun Date: Mon, 22 Jul 2019 16:21:27 -0500 Subject: [PATCH 5/9] Fix test --- pandas/tests/frame/test_alter_axes.py | 19 ++++++------------- pandas/tests/series/test_alter_axes.py | 9 +++------ 2 files changed, 9 insertions(+), 19 deletions(-) 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 b1f4f0839722219e0f8116bfd81c74b6fcdd5f6e Mon Sep 17 00:00:00 2001 From: pilkibun Date: Mon, 22 Jul 2019 16:23:25 -0500 Subject: [PATCH 6/9] Raise on inplace=None --- pandas/core/generic.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 6c63a704014db..6c357258cca42 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -657,6 +657,8 @@ 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 fc9185265f568c0441f36b50ebb0ef264b0c1a2a Mon Sep 17 00:00:00 2001 From: pilkibun Date: Mon, 22 Jul 2019 17:48:36 -0500 Subject: [PATCH 7/9] CI From 4fec9a320b4731c5f17ea4f8d3daf61098297d70 Mon Sep 17 00:00:00 2001 From: pilkibun Date: Wed, 24 Jul 2019 15:40:14 -0500 Subject: [PATCH 8/9] CI From b2a23742667446566f9789b4ea9e298b6db926ac Mon Sep 17 00:00:00 2001 From: pilkibun Date: Thu, 25 Jul 2019 18:49:12 -0500 Subject: [PATCH 9/9] CI