Exemple #1
0
 def values(self):
     if self._is_legacy_format:
         # for legacy MultiIndex
         values = [np.asarray(lev).take(lab) for lev, lab in zip(self.levels, self.labels)]
         return lib.fast_zip(values)
     else:
         return self.view(np.ndarray)
Exemple #2
0
 def values(self):
     if self._is_legacy_format:
         # for legacy MultiIndex
         values = [np.asarray(lev).take(lab)
                   for lev, lab in zip(self.levels, self.labels)]
         return lib.fast_zip(values)
     else:
         return self.view(np.ndarray)
Exemple #3
0
    def _get_compressed_labels(self):
        all_labels = [ping.labels for ping in self.groupings]
        if self._overflow_possible:
            tups = lib.fast_zip(all_labels)
            labs, uniques, _ = algos.factorize(tups)

            if self.sort:
                uniques, labs = _reorder_by_uniques(uniques, labs)

            return labs, uniques
        else:
            if len(all_labels) > 1:
                group_index = get_group_index(all_labels, self.shape)
            else:
                group_index = all_labels[0]
            comp_ids, obs_group_ids = _compress_group_index(group_index)
            return comp_ids, obs_group_ids
Exemple #4
0
    def __new__(cls, levels=None, labels=None, sortorder=None, names=None):
        assert(len(levels) == len(labels))
        if len(levels) == 0:
            raise Exception('Must pass non-zero number of levels/labels')

        if len(levels) == 1:
            if names:
                name = names[0]
            else:
                name = None

            return Index(levels[0], name=name).take(labels[0])

        levels = [_ensure_index(lev) for lev in levels]
        labels = [np.asarray(labs, dtype=np.int32) for labs in labels]

        values = [np.asarray(lev).take(lab)
                  for lev, lab in zip(levels, labels)]
        subarr = lib.fast_zip(values).view(cls)

        subarr.levels = levels
        subarr.labels = labels

        if names is None:
            subarr.names = [None] * subarr.nlevels
        else:
            assert(len(names) == subarr.nlevels)
            subarr.names = list(names)

        # set the name
        for i, name in enumerate(subarr.names):
            subarr.levels[i].name = name

        if sortorder is not None:
            subarr.sortorder = int(sortorder)
        else:
            subarr.sortorder = sortorder

        return subarr
Exemple #5
0
    def __new__(cls, levels=None, labels=None, sortorder=None, names=None):
        assert len(levels) == len(labels)
        if len(levels) == 0:
            raise Exception("Must pass non-zero number of levels/labels")

        if len(levels) == 1:
            if names:
                name = names[0]
            else:
                name = None

            return Index(levels[0], name=name).take(labels[0])

        levels = [_ensure_index(lev) for lev in levels]
        labels = [np.asarray(labs, dtype=np.int32) for labs in labels]

        values = [np.asarray(lev).take(lab) for lev, lab in zip(levels, labels)]
        subarr = lib.fast_zip(values).view(cls)

        subarr.levels = levels
        subarr.labels = labels

        if names is None:
            subarr.names = [None] * subarr.nlevels
        else:
            assert len(names) == subarr.nlevels
            subarr.names = list(names)

        # set the name
        for i, name in enumerate(subarr.names):
            subarr.levels[i].name = name

        if sortorder is not None:
            subarr.sortorder = int(sortorder)
        else:
            subarr.sortorder = sortorder

        return subarr
Exemple #6
0
 def values(self):
     values = [np.asarray(lev).take(lab)
               for lev, lab in zip(self.levels, self.labels)]
     return lib.fast_zip(values)