Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEPR: NDFrame.set_axis inplace defaults to false #27525 #27600

Merged
merged 5 commits into from Jul 26, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion doc/source/whatsnew/v1.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:``)
This conversation was marked as resolved.
Show resolved Hide resolved
-

.. _whatsnew_1000.performance:
Expand Down Expand Up @@ -191,6 +191,10 @@ ExtensionArray
-


Other
This conversation was marked as resolved.
Show resolved Hide resolved
^^^^^


.. _whatsnew_1000.contributors:

Contributors
Expand Down
33 changes: 6 additions & 27 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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
Expand All @@ -616,35 +610,27 @@ 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
c 3 6

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
Expand All @@ -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.")
This conversation was marked as resolved.
Show resolved Hide resolved
if inplace:
setattr(self, self._get_axis_name(axis), labels)
else:
Expand Down
19 changes: 6 additions & 13 deletions pandas/tests/frame/test_alter_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
9 changes: 3 additions & 6 deletions pandas/tests/series/test_alter_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down