def _getitem_multilevel(self, key): loc = self.items.get_loc(key) if isinstance(loc, (slice, np.ndarray)): new_index = self.items[loc] result_index = _maybe_droplevels(new_index, key) new_values = self.values[loc, :, :] result = Panel(new_values, items=result_index, major_axis=self.major_axis, minor_axis=self.minor_axis) return result else: return self._get_item_cache(key)
def _getitem_multilevel(self, key): info = self._info_axis loc = info.get_loc(key) if isinstance(loc, (slice, np.ndarray)): new_index = info[loc] result_index = _maybe_droplevels(new_index, key) slices = [loc] + [slice(None) for x in range(self._AXIS_LEN - 1)] new_values = self.values[slices] d = self._construct_axes_dict(self._AXIS_ORDERS[1:]) d[self._info_axis_name] = result_index result = self._constructor(new_values, **d) return result else: return self._get_item_cache(key)
def _multilevel_index(self, key): values = self.values try: loc = self.index.get_loc(key) if isinstance(loc, slice): # TODO: what if a level contains tuples?? new_index = self.index[loc] new_index = _maybe_droplevels(new_index, key) return Series(values[loc], index=new_index) else: return values[loc] except KeyError: if isinstance(key, (int, np.integer)): return values[key] raise Exception('Requested index not in this series!')