def test_hierarchy_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(len(lvl2a), 2) self.assertEqual(len(lvl1a), 8) self.assertEqual(len(lvl0), 24) self.assertEqual(list(lvl2a.depths()), [1]) self.assertEqual(list(lvl1a.depths()), [2, 2, 2, 2]) self.assertEqual(list(lvl0.depths()), [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) ih = IndexHierarchy(lvl0) self.assertEqual(len(ih), 24) post = ih.loc_to_iloc(HLoc[['A', 'B', 'C'], slice('2018-01-01', '2018-01-04'), ['x', 'y']]) # this will break if we recognize this can be a slice self.assertEqual(post, list(range(len(ih)))) post = ih.loc_to_iloc(HLoc[['A', 'B', 'C'], slice('2018-01-01', '2018-01-04'), 'x']) self.assertEqual(post, list(range(0, len(ih), 2))) post = ih.loc_to_iloc(HLoc['C', '2018-01-03', 'y']) self.assertEqual(post, 21) post = ih.loc_to_iloc(HLoc['B', '2018-01-03':, 'y']) self.assertEqual(post, [13, 15]) post = ih.loc_to_iloc(HLoc[['B', 'C'], '2018-01-03']) self.assertEqual(post, [12, 13, 20, 21]) post = ih.loc_to_iloc(HLoc[['A', 'C'], :, 'y']) self.assertEqual(post, [1, 3, 5, 7, 17, 19, 21, 23]) post = ih.loc_to_iloc(HLoc[['A', 'C'], :, 'x']) self.assertEqual(post, [0, 2, 4, 6, 16, 18, 20, 22])
def test_index_level_dtypes_all_a(self) -> None: level0 = IndexLevel(index=Index(('a', 'b')), targets=None) post = tuple(level0.dtypes_iter()) self.assertEqual(post[0], np.dtype('<U1')) self.assertEqual(len(post), 1) self.assertEqual(level0.depth, next(level0.depths()))