8000 [BUG] exception handling of MultiIndex.__contains__ too narrow by makbigc · Pull Request #25268 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

[BUG] exception handling of MultiIndex.__contains__ too narrow #25268

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 5 commits into from
Feb 19, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Fix the bug (GH24570)
  • Loading branch information
makbigc committed Feb 12, 2019
commit c1c212397a84c53abfa7799a9bbf2bac29ae3f9d
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/test_multilevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -1711,6 +1711,14 @@ def test_repeat(self):
m_df = Series(data, index=m_idx)
assert m_df.repeat(3).shape == (3 * len(data), )

def test_in(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

can you call this test_contains and move next to pandas/tests/indexing/test_multiindex.py

# 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


class TestSorted(Base):
""" everything you wanted to test about sorting """
Expand Down
0