Skip to content

BUG: fix Index's __iadd__ methods #5053

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

Merged
merged 1 commit into from
Oct 2, 2013
Merged
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
1 change: 1 addition & 0 deletions doc/source/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ API Changes
data - allowing metadata changes.
- ``MultiIndex.astype()`` now only allows ``np.object_``-like dtypes and
now returns a ``MultiIndex`` rather than an ``Index``. (:issue:`4039`)
- Aliased ``__iadd__`` to ``__add__``. (:issue:`4996`)
- Added ``is_`` method to ``Index`` that allows fast equality comparison of
views (similar to ``np.may_share_memory`` but no false positives, and
changes on ``levels`` and ``labels`` setting on ``MultiIndex``).
Expand Down
1 change: 1 addition & 0 deletions pandas/core/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,7 @@ def __add__(self, other):
else:
return Index(self.view(np.ndarray) + other)

__iadd__ = __add__
__eq__ = _indexOp('__eq__')
__ne__ = _indexOp('__ne__')
__lt__ = _indexOp('__lt__')
Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,14 @@ def test_add_string(self):
self.assert_('a' not in index2)
self.assert_('afoo' in index2)

def test_iadd_string(self):
index = pd.Index(['a', 'b', 'c'])
# doesn't fail test unless there is a check before `+=`
self.assert_('a' in index)

index += '_x'
self.assert_('a_x' in index)

def test_diff(self):
first = self.strIndex[5:20]
second = self.strIndex[:10]
Expand Down