Пример #1
0
    def _getitem_next(self, head, tail, advanced):
        nplike = self.nplike  # noqa: F841

        if head == ():
            return self

        elif isinstance(head, int):
            raise NestedIndexError(self, head, "array is empty")

        elif isinstance(head, slice):
            raise NestedIndexError(self, head, "array is empty")

        elif ak._util.isstr(head):
            return self._getitem_next_field(head, tail, advanced)

        elif isinstance(head, list):
            return self._getitem_next_fields(head, tail, advanced)

        elif head is np.newaxis:
            return self._getitem_next_newaxis(tail, advanced)

        elif head is Ellipsis:
            return self._getitem_next_ellipsis(tail, advanced)

        elif isinstance(head, ak._v2.index.Index64):
            raise NestedIndexError(self, head, "array is empty")

        elif isinstance(head, ak._v2.contents.ListOffsetArray):
            raise NotImplementedError

        elif isinstance(head, ak._v2.contents.IndexedOptionArray):
            raise NotImplementedError

        else:
            raise AssertionError(repr(head))
Пример #2
0
    def _getitem_next(self, head, tail, advanced):
        nplike = self._nplike

        if head == ():
            return self

        elif isinstance(head, int):
            where = (slice(None), head) + tail

            try:
                out = self._data[where]
            except IndexError as err:
                raise NestedIndexError(self, (head, ) + tail, str(err))

            if hasattr(out, "shape") and len(out.shape) != 0:
                return NumpyArray(out, None, None, nplike=nplike)
            else:
                return out

        elif isinstance(head, slice) or head is np.newaxis or head is Ellipsis:
            where = (slice(None), head) + tail

            try:
                out = self._data[where]
            except IndexError as err:
                raise NestedIndexError(self, (head, ) + tail, str(err))
            out2 = NumpyArray(out, None, self._parameters, nplike=nplike)
            return out2
        elif ak._util.isstr(head):
            return self._getitem_next_field(head, tail, advanced)

        elif isinstance(head, list):
            return self._getitem_next_fields(head, tail, advanced)

        elif isinstance(head, ak._v2.index.Index64):
            if advanced is None:
                where = (slice(None), head.data) + tail
            else:
                where = (nplike.asarray(advanced.data), head.data) + tail

            try:
                out = self._data[where]
            except IndexError as err:
                raise NestedIndexError(self, (head, ) + tail, str(err))

            return NumpyArray(out, None, self._parameters, nplike=nplike)

        elif isinstance(head, ak._v2.contents.ListOffsetArray):
            raise NotImplementedError

        elif isinstance(head, ak._v2.contents.IndexedOptionArray):
            raise NotImplementedError

        else:
            raise AssertionError(repr(head))
Пример #3
0
 def _getitem_at(self, where):
     if where < 0:
         where += len(self)
     if not (0 <= where < len(self)):
         raise NestedIndexError(self, where)
     start, stop = self._offsets[where], self._offsets[where + 1]
     return self._content._getitem_range(slice(start, stop))
Пример #4
0
 def _getitem_at(self, where):
     if where < 0:
         where += len(self)
     if not (0 <= where < len(self)):
         raise NestedIndexError(self, where)
     tag, index = self._tags[where], self._index[where]
     return self._contents[tag]._getitem_at(index)
Пример #5
0
 def _getitem_at(self, where):
     if where < 0:
         where += len(self)
     if not (0 <= where < len(self)):
         raise NestedIndexError(self, where)
     start, stop = (where) * self._size, (where + 1) * self._size
     return self._content._getitem_range(slice(start, stop))
Пример #6
0
 def _getitem_at(self, where):
     if where < 0:
         where += len(self)
     if not (0 <= where < len(self)):
         raise NestedIndexError(self, where)
     if self._index[where] < 0:
         return None
     else:
         return self._content._getitem_at(self._index[where])
Пример #7
0
 def _getitem_at(self, where):
     if where < 0:
         where += len(self)
     if not (0 <= where < len(self)):
         raise NestedIndexError(self, where)
     if self._mask[where] == self._valid_when:
         return self._content._getitem_at(where)
     else:
         return None
Пример #8
0
    def _getitem_at(self, where):
        try:
            out = self._data[where]
        except IndexError as err:
            raise NestedIndexError(self, where, str(err))

        if hasattr(out, "shape") and len(out.shape) != 0:
            return NumpyArray(out, None, None, nplike=self._nplike)
        else:
            return out
Пример #9
0
 def _getitem_at(self, where):
     if where < 0:
         where += len(self)
     if not (0 <= where < len(self)):
         raise NestedIndexError(self, where)
     if self._lsb_order:
         bit = bool(self._mask[where // 8] & (1 << (where % 8)))
     else:
         bit = bool(self._mask[where // 8] & (128 >> (where % 8)))
     if bit == self._valid_when:
         return self._content._getitem_at(where)
     else:
         return None
Пример #10
0
    def _getitem_range(self, where):
        start, stop, step = where.indices(len(self))
        assert step == 1

        try:
            out = self._data[where]
        except IndexError as err:
            raise NestedIndexError(self, where, str(err))

        return NumpyArray(
            out,
            self._range_identifier(start, stop),
            self._parameters,
            nplike=self._nplike,
        )
Пример #11
0
    def _carry(self, carry, allow_lazy, exception):
        assert isinstance(carry, ak._v2.index.Index)

        nplike, where = carry.nplike, carry.data

        copied = allow_lazy == "copied"
        if not issubclass(where.dtype.type, np.int64):
            where = where.astype(np.int64)
            copied = True

        negative = where < 0
        if nplike.any(negative):
            if not copied:
                where = where.copy()
                copied = True
            where[negative] += self._length

        if nplike.any(where >= self._length):
            raise NestedIndexError(self, where)

        nextcarry = ak._v2.index.Index64.empty(len(where) * self._size, nplike)
        self._handle_error(
            nplike["awkward_RegularArray_getitem_carry", nextcarry.dtype.type,
                   where.dtype.type, ](
                       nextcarry.to(nplike),
                       where,
                       len(where),
                       self._size,
                   ),
            carry,
        )

        return RegularArray(
            self._content._carry(nextcarry, allow_lazy, exception),
            self._size,
            len(where),
            self._carry_identifier(carry, exception),
            self._parameters,
        )
Пример #12
0
 def _getitem_fields(self, where, only_fields=()):
     raise NestedIndexError(self, where, "not an array of records")
Пример #13
0
 def _getitem_at(self, where):
     raise NestedIndexError(self, where, "array is empty")
Пример #14
0
 def _getitem_at(self, where):
     if where < 0:
         where += len(self)
     if not (0 <= where < len(self)):
         raise NestedIndexError(self, where)
     return Record(self, where)