Skip to content

WIP/DEPR: Deprecate inplace=True #24063

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
22 changes: 10 additions & 12 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,11 @@ def reset_index(self, level=None, drop=False, name=None, inplace=False):
values. Uses ``self.name`` by default. This argument is ignored
when `drop` is True.
inplace : bool, default False
Modify the Series in place (do not create a new object).
Update the caller instead of returning a new object.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe want to update the Returns to say that inplace returns None


.. deprecated:: 0.24.0
Use ``s = s.reset_index()`` instead of
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks ok, is this how we do it elsewhere?

``s.reset_index(inplace=True)``

Returns
-------
Expand Down Expand Up @@ -1183,17 +1187,6 @@ def reset_index(self, level=None, drop=False, name=None, inplace=False):
3 4
Name: foo, dtype: int64

To update the Series in place, without generating a new one
set `inplace` to True. Note that it also requires ``drop=True``.

>>> s.reset_index(inplace=True, drop=True)
>>> s
0 1
1 2
2 3
3 4
Name: foo, dtype: int64

The `level` parameter is interesting for Series with a multi-level
index.

Expand Down Expand Up @@ -1223,6 +1216,11 @@ def reset_index(self, level=None, drop=False, name=None, inplace=False):
2 baz one 2
3 baz two 3
"""
if inplace:
msg = ('inplace has been deprecated, and will be removed in a '
'future version. Use ``s = s.reset_index()`` instead of '
'``s.reset_index(inplace=True)``')
warnings.warn(msg, FutureWarning, stacklevel=2)
inplace = validate_bool_kwarg(inplace, 'inplace')
if drop:
new_index = ibase.default_index(len(self))
Expand Down
3 changes: 2 additions & 1 deletion pandas/tests/series/test_alter_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ def test_reset_index(self):
# check inplace
s = ser.reset_index(drop=True)
s2 = ser
s2.reset_index(drop=True, inplace=True)
with tm.assert_produces_warning(FutureWarning):
s2.reset_index(drop=True, inplace=True)
tm.assert_series_equal(s, s2)

# level
Expand Down