Skip to content

Commit

Permalink
[BUG] exception handling of MultiIndex.__contains__ too narrow (panda…
Browse files Browse the repository at this point in the history
  • Loading branch information
makbigc authored and Pingviinituutti committed Feb 28, 2019
1 parent 0af02c2 commit 6beb9b3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
3 changes: 1 addition & 2 deletions doc/source/whatsnew/v0.25.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,9 @@ Missing
MultiIndex
^^^^^^^^^^

- Bug in which incorrect exception raised by :meth:`pd.Timedelta` when testing the membership of :class:`MultiIndex` (:issue:`24570`)
-
-
-


I/O
^^^
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ def __contains__(self, key):
try:
self.get_loc(key)
return True
except (LookupError, TypeError):
except (LookupError, TypeError, ValueError):
return False

contains = __contains__
Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/indexing/multiindex/test_multiindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,11 @@ def test_multi_nan_indexing(self):
name='a'),
Index(['C1', 'C2', 'C3', 'C4'], name='b')])
tm.assert_frame_equal(result, expected)

def test_contains(self):
# GH 24570
tx = pd.timedelta_range('09:30:00', '16:00:00', freq='30 min')
idx = MultiIndex.from_arrays([tx, np.arange(len(tx))])
assert tx[0] in idx
assert 'element_not_exit' not in idx
assert '0 day 09:30:00' in idx

0 comments on commit 6beb9b3

Please sign in to comment.