Skip to content

TST: raise InvalidIndexError with IntervalIndex.get_value and get_loc #33938

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 6 commits into from
May 9, 2020
Merged
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
32 changes: 32 additions & 0 deletions pandas/tests/indexes/interval/test_interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
)
import pandas._testing as tm
import pandas.core.common as com
from pandas.core.indexes.base import InvalidIndexError


@pytest.fixture(scope="class", params=[None, "foo"])
Expand Down Expand Up @@ -857,6 +858,37 @@ def test_is_all_dates(self):
year_2017_index = pd.IntervalIndex([year_2017])
assert not year_2017_index.is_all_dates

def test_get_loc_errors(self):
idx = IntervalIndex.from_tuples([(1, 3), (2, 4), (3, 5), (7, 10), (3, 10)])

# key is not scalar
# GH 31117
key = [5]
msg = str(key)
with pytest.raises(InvalidIndexError, match=msg):
idx.get_loc(key)

key = (2, 3)
msg = str(key)
with pytest.raises(InvalidIndexError, match=msg):
idx.get_loc(key)

def test_get_value_errors(self):
idx = IntervalIndex.from_tuples([(1, 3), (2, 4), (3, 5), (7, 10), (3, 10)])
s = pd.Series(range(len(idx)), index=idx)

# key is not scalar
# GH 31117
key = [5]
msg = str(key)
with pytest.raises(InvalidIndexError, match=msg):
idx.get_value(s, key)

key = (2, 3)
msg = str(key)
with pytest.raises(InvalidIndexError, match=msg):
idx.get_value(s, key)


def test_dir():
# GH#27571 dir(interval_index) should not raise
Expand Down