Пример #1
0
    def __init__(
        self,
        levels: tp.Union[IndexLevel, 'IndexHierarchy'],
    ):
        '''
        Args:
            levels: IndexLevels instance, or, optionally, an IndexHierarchy to be used to construct a new IndexHierarchy.
            labels: a client can optionally provide the labels used to construct the levels, as an optional optimization in forming the IndexHierarchy.
        '''

        if issubclass(levels.__class__, IndexHierarchy):
            if levels.STATIC:
                self._levels = levels._levels
            else:  # must deepcopy labels if not static
                self._levels = levels._levels.to_index_level()

            self._labels = levels.values
            self._depth = levels.depth
            self._keys = levels.keys()  # immutable keys view can be shared
            self._length = self._labels.__len__()  #levels.__len__()
            self._recache = False
        elif isinstance(levels, IndexLevel):
            self._levels = levels
            # vlaues derived from levels are deferred
            self._labels = None
            self._depth = None
            self._keys = None
            self._length = None
            self._recache = True
        else:
            raise NotImplementedError('no handling for creation from', levels)

        self.loc = GetItem(self._extract_loc)
        self.iloc = GetItem(self._extract_iloc)
Пример #2
0
 def iloc(self) -> GetItem:
     return GetItem(self._extract_iloc)
Пример #3
0
 def loc(self):
     return GetItem(self._extract_loc)