Skip to content

Commit 93f75ea

Browse files
Refactor interval index get_loc test
Move the test from indexing/test_loc to index/interval/test_interval.
1 parent 246eb57 commit 93f75ea

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

pandas/tests/indexes/interval/test_interval.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,14 @@ def test_get_loc_value(self):
435435
idx = IntervalIndex.from_arrays([0, 2], [1, 3])
436436
pytest.raises(KeyError, idx.get_loc, 1.5)
437437

438+
# GH25087, test get_loc returns key error for interval indexes
439+
msg = 'key is hashable but of incorrect type'
440+
with pytest.raises(KeyError, match=msg):
441+
idx.get_loc('a')
442+
idx = pd.interval_range(0, 1.0)
443+
with pytest.raises(KeyError, match=msg):
444+
idx.get_loc('a')
445+
438446
# To be removed, replaced by test_interval_new.py (see #16316, #16386)
439447
def slice_locs_cases(self, breaks):
440448
# TODO: same tests for more index types

pandas/tests/indexing/test_loc.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -778,9 +778,3 @@ def test_loc_setitem_empty_append_raises(self):
778778
msg = "cannot copy sequence with size 2 to array axis with dimension 0"
779779
with pytest.raises(ValueError, match=msg):
780780
df.loc[0:2, 'x'] = data
781-
782-
def test_loc_getitem_interval_index(self):
783-
""" GH25087, test get_loc returns key error for interval indexes"""
784-
idx = pd.interval_range(0, 1.0)
785-
with pytest.raises(KeyError):
786-
idx.get_loc('gg')

0 commit comments

Comments
 (0)