MCPcopy
hub / github.com/pandas-dev/pandas / test_get_loc

Method test_get_loc

pandas/tests/indexes/multi/test_indexing.py:588–607  ·  view source on GitHub ↗
(self, idx)

Source from the content-addressed store, hash-verified

586
587class TestGetLoc:
588 def test_get_loc(self, idx):
589 assert idx.get_loc(("foo", "two")) == 1
590 assert idx.get_loc(("baz", "two")) == 3
591 with pytest.raises(KeyError, match=r"^\('bar', 'two'\)$"):
592 idx.get_loc(("bar", "two"))
593 with pytest.raises(KeyError, match=r"^'quux'$"):
594 idx.get_loc("quux")
595
596 # 3 levels
597 index = MultiIndex(
598 levels=[Index(np.arange(4)), Index(np.arange(4)), Index(np.arange(4))],
599 codes=[
600 np.array([0, 0, 1, 2, 2, 2, 3, 3]),
601 np.array([0, 1, 0, 0, 0, 1, 0, 1]),
602 np.array([1, 0, 1, 1, 0, 0, 1, 0]),
603 ],
604 )
605 with pytest.raises(KeyError, match=r"^\(1, 1\)$"):
606 index.get_loc((1, 1))
607 assert index.get_loc((2, 0)) == slice(3, 5)
608
609 def test_get_loc_duplicates(self):
610 index = Index([2, 2, 2, 2])

Callers

nothing calls this directly

Calls 6

get_locMethod · 0.95
MultiIndexClass · 0.90
IndexClass · 0.90
get_locMethod · 0.45
raisesMethod · 0.45
arrayMethod · 0.45

Tested by

no test coverage detected