ak.contents.ListArray#

Defined in awkward.contents.listarray on line 52.

class ak.contents.ListArray(self, starts, stops, content, *, parameters=None)#

ListArray generalizes ak.contents.ListOffsetArray by not requiring its content to be in increasing order and by allowing it to have unreachable elements between lists. Instead of a single offsets buffer, ListArray has

  • starts: The starting index of each list.

  • stops: The stopping index of each list.

ak.contents.ListOffsetArray offsets may be related to starts and stops by

starts = offsets[:-1]
stops = offsets[1:]

ListArrays are a common by-product of structure manipulation: as a result of some operation, we might want to view slices or permutations of the content without copying it to make a contiguous version of it. For that reason, ListArrays are more useful in a data-manipulation library like Awkward Array than in a data-representation library like Apache Arrow.

Like ak.contents.ListOffsetArray and ak.contents.RegularArray, a ListArray 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).

There is no equivalent of ListArray in Apache Arrow.

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

class ListArray(Content):
    def __init__(self, starts, stops, content):
        assert isinstance(starts, (Index32, IndexU32, Index64))
        assert isinstance(stops, type(starts))
        assert isinstance(content, Content)
        assert len(stops) >= len(starts)  # usually equal
        for i in range(len(starts)):
            start = starts[i]
            stop = stops[i]
            if start != stop:
                assert start < stop  # i.e. start <= stop
                assert start >= 0
                assert stop <= len(content)
        self.starts = starts
        self.stops = stops
        self.content = content

    def __len__(self):
        return len(self.starts)

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

        elif isinstance(where, slice) and where.step is None:
            starts = self.starts[where.start : where.stop]
            stops = self.stops[where.start : where.stop]
            return ListArray(starts, stops, self.content)

        elif isinstance(where, str):
            return ListArray(self.starts, self.stops, self.content[where])

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