Skip to content

Commit c06a21f

Browse files
primaprashantrhshadrach
authored andcommitted
TST: raise InvalidIndexError with IntervalIndex.get_value and get_loc (#33938)
1 parent 5f4b905 commit c06a21f

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

pandas/tests/indexes/interval/test_indexing.py

+9
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,15 @@ def test_get_loc_decreasing(self, values):
158158
expected = 0
159159
assert result == expected
160160

161+
@pytest.mark.parametrize("key", [[5], (2, 3)])
162+
def test_get_loc_non_scalar_errors(self, key):
163+
# GH 31117
164+
idx = IntervalIndex.from_tuples([(1, 3), (2, 4), (3, 5), (7, 10), (3, 10)])
165+
166+
msg = str(key)
167+
with pytest.raises(InvalidIndexError, match=msg):
168+
idx.get_loc(key)
169+
161170

162171
class TestGetIndexer:
163172
@pytest.mark.parametrize(

pandas/tests/indexes/interval/test_interval.py

+12
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
)
2020
import pandas._testing as tm
2121
import pandas.core.common as com
22+
from pandas.core.indexes.base import InvalidIndexError
2223

2324

2425
@pytest.fixture(scope="class", params=[None, "foo"])
@@ -857,6 +858,17 @@ def test_is_all_dates(self):
857858
year_2017_index = pd.IntervalIndex([year_2017])
858859
assert not year_2017_index.is_all_dates
859860

861+
@pytest.mark.parametrize("key", [[5], (2, 3)])
862+
def test_get_value_non_scalar_errors(self, key):
863+
# GH 31117
864+
idx = IntervalIndex.from_tuples([(1, 3), (2, 4), (3, 5), (7, 10), (3, 10)])
865+
s = pd.Series(range(len(idx)), index=idx)
866+
867+
msg = str(key)
868+
with pytest.raises(InvalidIndexError, match=msg):
869+
with tm.assert_produces_warning(FutureWarning):
870+
idx.get_value(s, key)
871+
860872

861873
def test_dir():
862874
# GH#27571 dir(interval_index) should not raise

0 commit comments

Comments
 (0)