Skip to content

Commit dfea876

Browse files
authored
BUG: Series.reset_index not ignoring name with inplace and drop (#44578)
1 parent 7f43278 commit dfea876

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

doc/source/whatsnew/v1.4.0.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ Datetimelike
552552
- Bug in constructing a :class:`Series` from datetime-like strings with mixed timezones incorrectly partially-inferring datetime values (:issue:`40111`)
553553
- Bug in addition with a :class:`Tick` object and a ``np.timedelta64`` object incorrectly raising instead of returning :class:`Timedelta` (:issue:`44474`)
554554
- Bug in adding a ``np.timedelta64`` object to a :class:`BusinessDay` or :class:`CustomBusinessDay` object incorrectly raising (:issue:`44532`)
555-
- Bug in :meth:`Index.insert` for inserting ``np.datetime64``, ``np.timedelta64`` or ``tuple`` into :class:`Index` with ``dtype='object'`` with negative loc addine ``None`` and replacing existing value (:issue:`44509`)
555+
- Bug in :meth:`Index.insert` for inserting ``np.datetime64``, ``np.timedelta64`` or ``tuple`` into :class:`Index` with ``dtype='object'`` with negative loc adding ``None`` and replacing existing value (:issue:`44509`)
556556
-
557557

558558
Timedelta
@@ -620,6 +620,7 @@ Indexing
620620
- Bug when setting string-backed :class:`Categorical` values that can be parsed to datetimes into a :class:`DatetimeArray` or :class:`Series` or :class:`DataFrame` column backed by :class:`DatetimeArray` failing to parse these strings (:issue:`44236`)
621621
- Bug in :meth:`Series.__setitem__` with an integer dtype other than ``int64`` setting with a ``range`` object unnecessarily upcasting to ``int64`` (:issue:`44261`)
622622
- Bug in :meth:`Series.__setitem__` with a boolean mask indexer setting a listlike value of length 1 incorrectly broadcasting that value (:issue:`44265`)
623+
- Bug in :meth:`Series.reset_index` not ignoring ``name`` argument when ``drop`` and ``inplace`` are set to ``True`` (:issue:`44575`)
623624
- Bug in :meth:`DataFrame.loc.__setitem__` and :meth:`DataFrame.iloc.__setitem__` with mixed dtypes sometimes failing to operate in-place (:issue:`44345`)
624625
- Bug in :meth:`DataFrame.loc.__getitem__` incorrectly raising ``KeyError`` when selecting a single column with a boolean key (:issue:`44322`).
625626
- Bug in indexing on columns with ``loc`` or ``iloc`` using a slice with a negative step with ``ExtensionDtype`` columns incorrectly raising (:issue:`44551`)

pandas/core/series.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,9 +1449,6 @@ def reset_index(self, level=None, drop=False, name=lib.no_default, inplace=False
14491449
"""
14501450
inplace = validate_bool_kwarg(inplace, "inplace")
14511451
if drop:
1452-
if name is lib.no_default:
1453-
name = self.name
1454-
14551452
new_index = default_index(len(self))
14561453
if level is not None:
14571454
if not isinstance(level, (tuple, list)):
@@ -1462,8 +1459,6 @@ def reset_index(self, level=None, drop=False, name=lib.no_default, inplace=False
14621459

14631460
if inplace:
14641461
self.index = new_index
1465-
# set name if it was passed, otherwise, keep the previous name
1466-
self.name = name or self.name
14671462
else:
14681463
return self._constructor(
14691464
self._values.copy(), index=new_index

pandas/tests/series/methods/test_reset_index.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,13 @@ def test_drop_pos_args_deprecation(self):
160160
expected = DataFrame({"a": [1, 2, 3], 0: [1, 2, 3]})
161161
tm.assert_frame_equal(result, expected)
162162

163+
def test_reset_index_inplace_and_drop_ignore_name(self):
164+
# GH#44575
165+
ser = Series(range(2), name="old")
166+
ser.reset_index(name="new", drop=True, inplace=True)
167+
expected = Series(range(2), name="old")
168+
tm.assert_series_equal(ser, expected)
169+
163170

164171
@pytest.mark.parametrize(
165172
"array, dtype",

0 commit comments

Comments
 (0)