Skip to content

Commit c66a5fd

Browse files
committed
BUG: Fix Index.__iadd__ bug by setting equal to __add__
fixes pandas-dev#4996 alias Index's __isub__ to __sub__ document fixes to pandas-dev#4996 index isub test roll back everything non-iadd related
1 parent 609d6a6 commit c66a5fd

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

doc/source/release.rst

+1
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ API Changes
214214
data - allowing metadata changes.
215215
- ``MultiIndex.astype()`` now only allows ``np.object_``-like dtypes and
216216
now returns a ``MultiIndex`` rather than an ``Index``. (:issue:`4039`)
217+
- Aliased ``__iadd__`` to ``__add__``. (:issue:`4996`)
217218
- Added ``is_`` method to ``Index`` that allows fast equality comparison of
218219
views (similar to ``np.may_share_memory`` but no false positives, and
219220
changes on ``levels`` and ``labels`` setting on ``MultiIndex``).

pandas/core/index.py

+1
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,7 @@ def __add__(self, other):
832832
else:
833833
return Index(self.view(np.ndarray) + other)
834834

835+
__iadd__ = __add__
835836
__eq__ = _indexOp('__eq__')
836837
__ne__ = _indexOp('__ne__')
837838
__lt__ = _indexOp('__lt__')

pandas/tests/test_index.py

+8
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,14 @@ def test_add_string(self):
382382
self.assert_('a' not in index2)
383383
self.assert_('afoo' in index2)
384384

385+
def test_iadd_string(self):
386+
index = pd.Index(['a', 'b', 'c'])
387+
# doesn't fail test unless there is a check before `+=`
388+
self.assert_('a' in index)
389+
390+
index += '_x'
391+
self.assert_('a_x' in index)
392+
385393
def test_diff(self):
386394
first = self.strIndex[5:20]
387395
second = self.strIndex[:10]

0 commit comments

Comments
 (0)