ak.contents.ListOffsetArray#

Defined in awkward.contents.listoffsetarray on line 54.

class ak.contents.ListOffsetArray(self, offsets, content, *, parameters=None)#

ListOffsetArray describes unequal-length lists (often called a “jagged” or “ragged” array). Like ak.contents.RegularArray, the underlying data for all lists are in a contiguous content. It is subdivided into lists according to an offsets buffer, which specifies the starting and stopping index of each list.

The offsets must have at least length 1 (corresponding to an empty array), but it need not start with 0 or include all of the content. Just as ak.contents.RegularArray can have unreachable content if it is not an integer multiple of size, a ListOffsetArray can have unreachable content before the start of the first list and after the end of the last list.

Like ak.contents.RegularArray and ak.contents.ListArray, a ListOffsetArray can represent strings if its __array__ parameter is "string" (UTF-8 assumed) or "bytestring" (no encoding assumed) and it contains an ak.contents.NumpyArray of dtype=np.uint8 whose __array__ parameter is "char" (UTF-8 assumed) or "byte" (no encoding assumed).

ListOffsetArray corresponds to Apache Arrow List type.

To illustrate how the constructor arguments are interpreted, the following is a simplified implementation of __init__, __len__, and __getitem__:

class ListOffsetArray(Content):
    def __init__(self, offsets, content):
        assert isinstance(offsets, (Index32, IndexU32, Index64))
        assert isinstance(content, Content)
        assert len(offsets) != 0
        for i in range(len(offsets) - 1):
            start = offsets[i]
            stop = offsets[i + 1]
            if start != stop:
                assert start < stop  # i.e. start <= stop
                assert start >= 0
                assert stop <= len(content)
        self.offsets = offsets
        self.content = content

    def __len__(self):
        return len(self.offsets) - 1

    def __getitem__(self, where):
        if isinstance(where, int):
            if where < 0:
                where += len(self)
            assert 0 <= where < len(self)
            return self.content[self.offsets[where] : self.offsets[where + 1]]

        elif isinstance(where, slice) and where.step is None:
            offsets = self.offsets[where.start : where.stop + 1]
            if len(offsets) == 0:
                offsets = [0]
            return ListOffsetArray(offsets, self.content)

        elif isinstance(where, str):
            return ListOffsetArray(self.offsets, self.content[where])

        else:
            raise AssertionError(where)
ak.contents.ListOffsetArray.offsets#
ak.contents.ListOffsetArray.copy(self, offsets=UNSET, content=UNSET, *, parameters=UNSET)#
ak.contents.ListOffsetArray.__copy__(self)#
ak.contents.ListOffsetArray.__deepcopy__(self, memo)#
ak.contents.ListOffsetArray.simplified(cls, offsets, content, *, parameters=None)#
ak.contents.ListOffsetArray.starts#
ak.contents.ListOffsetArray.stops#
ak.contents.ListOffsetArray._form_with_key(self, getkey)#
ak.contents.ListOffsetArray._to_buffers(self, form, getkey, container, backend, byteorder)#
ak.contents.ListOffsetArray._to_typetracer(self, forget_length)#
ak.contents.ListOffsetArray._touch_data(self, recursive)#
ak.contents.ListOffsetArray._touch_shape(self, recursive)#
ak.contents.ListOffsetArray.length#
ak.contents.ListOffsetArray.__repr__(self)#
ak.contents.ListOffsetArray._repr(self, indent, pre, post)#
ak.contents.ListOffsetArray.to_ListOffsetArray64(self, start_at_zero=False)#
ak.contents.ListOffsetArray.to_RegularArray(self)#
ak.contents.ListOffsetArray._getitem_nothing(self)#
ak.contents.ListOffsetArray._is_getitem_at_placeholder(self)#
ak.contents.ListOffsetArray._getitem_at(self, where)#
ak.contents.ListOffsetArray._getitem_range(self, start, stop)#
ak.contents.ListOffsetArray._getitem_field(self, where, only_fields=())#
ak.contents.ListOffsetArray._getitem_fields(self, where, only_fields=())#
ak.contents.ListOffsetArray._carry(self, carry, allow_lazy)#
ak.contents.ListOffsetArray._compact_offsets64(self, start_at_zero)#
ak.contents.ListOffsetArray._broadcast_tooffsets64(self, offsets)#
ak.contents.ListOffsetArray._getitem_next_jagged(self, slicestarts, slicestops, slicecontent, tail)#
ak.contents.ListOffsetArray._getitem_next(self, head, tail, advanced)#
ak.contents.ListOffsetArray._offsets_and_flattened(self, axis, depth)#
ak.contents.ListOffsetArray._mergeable_next(self, other, mergebool)#
ak.contents.ListOffsetArray._mergemany(self, others)#
ak.contents.ListOffsetArray._fill_none(self, value)#
ak.contents.ListOffsetArray._local_index(self, axis, depth)#
ak.contents.ListOffsetArray._numbers_to_type(self, name, including_unknown)#
ak.contents.ListOffsetArray._is_unique(self, negaxis, starts, parents, outlength)#
ak.contents.ListOffsetArray._unique(self, negaxis, starts, parents, outlength)#
ak.contents.ListOffsetArray._argsort_next(self, negaxis, starts, shifts, parents, outlength, ascending, stable)#
ak.contents.ListOffsetArray._sort_next(self, negaxis, starts, parents, outlength, ascending, stable)#
ak.contents.ListOffsetArray._combinations(self, n, replacement, recordlookup, parameters, axis, depth)#
ak.contents.ListOffsetArray._reduce_next(self, reducer, negaxis, starts, shifts, parents, outlength, mask, keepdims, behavior)#
ak.contents.ListOffsetArray._rearrange_prepare_next(self, outlength, parents)#
ak.contents.ListOffsetArray._validity_error(self, path)#
ak.contents.ListOffsetArray._nbytes_part(self)#
ak.contents.ListOffsetArray._pad_none(self, target, axis, depth, clip)#
ak.contents.ListOffsetArray._to_arrow(self, pyarrow, mask_node, validbytes, length, options)#
ak.contents.ListOffsetArray._to_cudf(self, cudf, mask, length)#
ak.contents.ListOffsetArray._to_backend_array(self, allow_missing, backend)#
ak.contents.ListOffsetArray._remove_structure(self, backend, options)#
ak.contents.ListOffsetArray._drop_none(self)#
ak.contents.ListOffsetArray._rebuild_without_nones(self, none_indexes, new_content)#
ak.contents.ListOffsetArray._recursively_apply(self, action, depth, depth_context, lateral_context, options)#
ak.contents.ListOffsetArray.to_packed(self, recursive=True)#
ak.contents.ListOffsetArray._to_list(self, behavior, json_conversions)#
ak.contents.ListOffsetArray._to_backend(self, backend)#
ak.contents.ListOffsetArray._awkward_strings_to_nonfinite(self, nonfinit_dict)#
ak.contents.ListOffsetArray._is_equal_to(self, other, index_dtype, numpyarray, all_parameters)#