def test_index_level_leaf_loc_to_iloc_c(self) -> None: groups = Index(('A', 'B', 'C')) dates = IndexDate.from_date_range('2018-01-01', '2018-01-04') observations = Index(('x', 'y')) lvl2a = IndexLevel(index=observations) lvl2b = IndexLevel(index=observations, offset=2) lvl2c = IndexLevel(index=observations, offset=4) lvl2d = IndexLevel(index=observations, offset=6) lvl2_targets = ArrayGO((lvl2a, lvl2b, lvl2c, lvl2d)) lvl1a = IndexLevel(index=dates, targets=lvl2_targets, offset=0) lvl1b = IndexLevel(index=dates, targets=lvl2_targets, offset=len(lvl1a)) lvl1c = IndexLevel(index=dates, targets=lvl2_targets, offset=len(lvl1a) * 2) lvl0 = IndexLevel(index=groups, targets=ArrayGO((lvl1a, lvl1b, lvl1c))) with self.assertRaises(KeyError): lvl0.leaf_loc_to_iloc(('A')) self.assertEqual(lvl0.leaf_loc_to_iloc(('A', '2018-01-01', 'y')), 1)
def test_index_level_leaf_loc_to_iloc_a(self): groups = Index(('A', 'B', 'C')) dates = IndexDate.from_date_range('2018-01-01', '2018-01-04') observations = Index(('x', 'y')) lvl2a = IndexLevel(index=observations) lvl2b = IndexLevel(index=observations, offset=2) lvl2c = IndexLevel(index=observations, offset=4) lvl2d = IndexLevel(index=observations, offset=6) lvl2_targets = ArrayGO((lvl2a, lvl2b, lvl2c, lvl2d)) lvl1a = IndexLevel(index=dates, targets=lvl2_targets, offset=0) lvl1b = IndexLevel(index=dates, targets=lvl2_targets, offset=len(lvl1a)) lvl1c = IndexLevel(index=dates, targets=lvl2_targets, offset=len(lvl1a) * 2) # we need as many targets as len(index) lvl0 = IndexLevel(index=groups, targets=ArrayGO((lvl1a, lvl1b, lvl1c))) self.assertEqual(lvl0.leaf_loc_to_iloc(('B', '2018-01-04', 'y'),), 15) self.assertEqual(lvl0.leaf_loc_to_iloc(('A', '2018-01-01', 'y')), 1)
def test_index_level_leaf_loc_to_iloc_b(self) -> None: level0 = IndexLevel(index=Index(('a', 'b')), targets=None) self.assertEqual(level0.leaf_loc_to_iloc(('b',)), 1) self.assertEqual(level0.leaf_loc_to_iloc(ILoc[1]), 1)