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
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
9 changes: 9 additions & 0 deletions pandas/tests/indexes/interval/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,15 @@ def test_get_loc_decreasing(self, values):
expected = 0
assert result == expected

@pytest.mark.parametrize("key", [[5], (2, 3)])
def test_get_loc_non_scalar_errors(self, key):
# GH 31117
idx = IntervalIndex.from_tuples([(1, 3), (2, 4), (3, 5), (7, 10), (3, 10)])

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


class TestGetIndexer:
@pytest.mark.parametrize(
Expand Down
12 changes: 12 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,17 @@ def test_is_all_dates(self):
year_2017_index = pd.IntervalIndex([year_2017])
assert not year_2017_index.is_all_dates

@pytest.mark.parametrize("key", [[5], (2, 3)])
def test_get_value_non_scalar_errors(self, key):
# GH 31117
idx = IntervalIndex.from_tuples([(1, 3), (2, 4), (3, 5), (7, 10), (3, 10)])
s = pd.Series(range(len(idx)), index=idx)

msg = str(key)
with pytest.raises(InvalidIndexError, match=msg):
with tm.assert_produces_warning(FutureWarning):
idx.get_value(s, key)


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