示例#1
0
    def shapes(self) -> Series:
        '''A :obj:`Series` describing the shape of each loaded :obj:`Frame`. Unloaded :obj:`Frame` will have a shape of None.

        Returns:
            :obj:`tp.Series`
        '''
        return Series.from_concat((b.shapes for b in self._series.values),
                                  index=self._index)
示例#2
0
 def from_concat(cls,
         containers: tp.Iterable['Bus'],
         *,
         index: tp.Optional[tp.Union[IndexInitializer, IndexAutoFactoryType]] = None,
         name: NameType = NAME_DEFAULT,
         ) -> 'Bus':
     '''
     Concatenate multiple :obj:`Bus` into a new :obj:`Bus`. All :obj:`Bus` will load all :obj:`Frame` into memory if any are deferred.
     '''
     # will extract .values, .index from Bus, which will correct load from Store as needed
     series = Series.from_concat(containers, index=index, name=name)
     return cls(series, own_data=True)
示例#3
0
    def _extract(self,
            row_key: GetItemKeyType = None,
            column_key: GetItemKeyType = None,
            ) -> tp.Union[Frame, Series]:
        '''
        Extract Container based on iloc selection.
        '''
        assert self._axis_hierarchy is not None #mypy

        extractor = get_extractor(
                self._deepcopy_from_bus,
                is_array=False,
                memo_active=False,
                )

        row_key = NULL_SLICE if row_key is None else row_key
        row_key_is_array = isinstance(row_key, np.ndarray)
        column_key = NULL_SLICE if column_key is None else column_key
        column_key_is_array = isinstance(column_key, np.ndarray)

        if (not row_key_is_array and row_key == NULL_SLICE
                and not column_key_is_array and column_key == NULL_SLICE):
            if self._retain_labels and self._axis == 0:
                frames = (extractor(f.relabel_level_add(index=k))
                        for k, f in self._bus.items())
            elif self._retain_labels and self._axis == 1:
                frames = (extractor(f.relabel_level_add(columns=k))
                        for k, f in self._bus.items())
            else:
                frames = (extractor(f) for _, f in self._bus.items())

            return Frame.from_concat( #type: ignore
                    frames,
                    axis=self._axis,
                    )

        parts: tp.List[tp.Any] = []
        frame_labels: tp.Iterable[tp.Hashable]

        if self._axis == 0:
            sel_key = row_key
            opposite_key = column_key
        else:
            sel_key = column_key
            opposite_key = row_key

        sel_reduces = isinstance(sel_key, INT_TYPES)

        sel = np.full(len(self._axis_hierarchy), False)
        sel[sel_key] = True

        # get ordered unique Bus labels
        axis_map_sub = self._axis_hierarchy.iloc[sel_key]
        if isinstance(axis_map_sub, tuple): #type: ignore
            frame_labels = (axis_map_sub[0],) #type: ignore
        else:
            # get the outer level, or just the unique frame labels needed
            frame_labels = axis_map_sub._levels.index

        for key_count, key in enumerate(frame_labels):
            # get Boolean segment for this Frame
            sel_component = sel[self._axis_hierarchy._loc_to_iloc(HLoc[key])]

            if self._axis == 0:
                component = self._bus.loc[key].iloc[sel_component, opposite_key]
                if key_count == 0:
                    component_is_series = isinstance(component, Series)
                if self._retain_labels:
                    # component might be a Series, can call the same with first arg
                    component = component.relabel_level_add(key)
                if sel_reduces: # make Frame into a Series, Series into an element
                    component = component.iloc[0]
            else:
                component = self._bus.loc[key].iloc[opposite_key, sel_component]
                if key_count == 0:
                    component_is_series = isinstance(component, Series)
                if self._retain_labels:
                    if component_is_series:
                        component = component.relabel_level_add(key)
                    else:
                        component = component.relabel_level_add(columns=key)
                if sel_reduces: # make Frame into a Series, Series into an element
                    if component_is_series:
                        component = component.iloc[0]
                    else:
                        component = component.iloc[NULL_SLICE, 0]

            parts.append(extractor(component))

        if len(parts) == 1:
            return parts.pop() #type: ignore

        # NOTE: Series/Frame from_concate will attempt to re-use ndarrays, and thus using extractor above is appropriate
        if component_is_series:
            return Series.from_concat(parts)
        return Frame.from_concat(parts, axis=self._axis) #type: ignore
示例#4
0
 def mloc(self) -> Series:
     '''Returns a :obj:`Series` showing a tuple of memory locations within each loaded Frame.
     '''
     return Series.from_concat((b.mloc for b in self._series.values),
                               index=self._index)