예제 #1
0
파일: multiindex.py 프로젝트: jimmytuc/cudf
 def take(self, indices):
     from collections.abc import Sequence
     from cudf import Series
     from numbers import Integral
     if isinstance(indices, (Integral, Sequence)):
         indices = np.array(indices)
     elif isinstance(indices, Series):
         indices = indices.to_gpu_array()
     elif isinstance(indices, slice):
         start, stop, step, sln = utils.standard_python_slice(len(self),
                                                              indices)
         indices = np.arange(start, stop, step)
     codes = self.codes.take(indices)
     result = MultiIndex(self.levels, codes)
     result.names = self.names
     return result
예제 #2
0
    def __getitem__(self, arg):
        rows = []
        len_idx = len(self._sr)

        if isinstance(arg, tuple):
            for idx in arg:
                rows.append(idx)

        elif isinstance(arg, int):
            rows.append(arg)

        elif isinstance(arg, slice):
            start, stop, step, sln = utils.standard_python_slice(len_idx, arg)
            if sln > 0:
                for idx in range(start, stop, step):
                    rows.append(idx)

        else:
            raise TypeError(type(arg))

        # To check whether all the indices are valid.
        for idx in rows:
            if abs(idx) > len_idx or idx == len_idx:
                raise IndexError("positional indexers are out-of-bounds")

        for i in range(len(rows)):
            if rows[i] < 0:
                rows[i] = len_idx + rows[i]

        # returns the single elem similar to pandas
        if isinstance(arg, int) and len(rows) == 1:
            return self._sr[rows[0]]

        ret_list = []
        for idx in rows:
            ret_list.append(self._sr[idx])

        col_data = columnops.as_column(ret_list,
                                       dtype=self._sr.dtype,
                                       nan_as_null=True)

        return Series(col_data, index=as_index(np.asarray(rows)))
예제 #3
0
    def __getitem__(self, index):
        if isinstance(index, slice):
            start, stop, step, sln = utils.standard_python_slice(
                len(self), index)
            start += self._start
            stop += self._start
            if sln == 0:
                return RangeIndex(0)
            else:
                return index_from_range(start, stop, step)

        elif isinstance(index, int):
            index = utils.normalize_index(index, len(self))
            index += self._start
            return index
        elif isinstance(index, (list, np.ndarray)):
            index = np.array(index)
            index = rmm.to_device(index)

        if isinstance(index, (DeviceNDArray)):
            return self.take(index)
        else:
            raise ValueError(index)