ak.contents.RecordArray#

Defined in awkward.contents.recordarray on line 114.

class ak.contents.RecordArray(contents: collections.abc.Iterable[awkward.contents.content.Content], fields: collections.abc.Iterable[str] | None, length: int | type[awkward._nplikes.shape.unknown_length] | None = None, length_generator: awkward._typing.Callable[[], awkward._nplikes.shape.ShapeItem] | None = None, *, parameters=None, backend=None)#

RecordArray represents an array of tuples or records, all with the same type. Its contents is an ordered list of arrays.

  • If fields is None, the data are tuples, indexed only by their order.

  • Otherwise, fields is an ordered list of names with the same length as the contents, associating a field name to every content.

The length of the RecordArray, if not given, is the length of its shortest content; all are aligned element-by-element. If a RecordArray has zero contents, it may still represent a non-empty array. In that case, its length is specified by a length parameter.

RecordArrays correspond to Apache Arrow’s struct type.

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

class RecordArray(Content):
    def __init__(self, contents, fields, length):
        assert isinstance(contents, list)
        assert isinstance(length, int)
        for x in contents:
            assert isinstance(x, Content)
            assert len(x) >= length
        assert fields is None or isinstance(fields, list)
        if isinstance(fields, list):
            assert len(fields) == len(contents)
            for x in fields:
                assert isinstance(x, str)
        self.contents = contents
        self.fields = fields
        self.length = length

    def __len__(self):
        return self.length

    def __getitem__(self, where):
        if isinstance(where, int):
            if where < 0:
                where += len(self)
            assert 0 <= where < len(self)
            record = [x[where] for x in self.contents]
            if self.fields is None:
                return tuple(record)
            else:
                return dict(zip(self.fields, record))

        elif isinstance(where, slice) and where.step is None:
            if len(self.contents) == 0:
                start = min(max(where.start, 0), self.length)
                stop = min(max(where.stop, 0), self.length)
                if stop < start:
                    stop = start
                return RecordArray([], self.fields, stop - start)
            else:
                return RecordArray(
                    [x[where] for x in self.contents],
                    self.fields,
                    where.stop - where.start,
                )

        elif isinstance(where, str):
            if self.fields is None:
                try:
                    i = int(where)
                except ValueError:
                    pass
                else:
                    if i < len(self.contents):
                        return self.contents[i][0 : len(self)]
            else:
                try:
                    i = self.fields.index(where)
                except ValueError:
                    pass
                else:
                    return self.contents[i][0 : len(self)]
            raise ValueError("field " + repr(where) + " not found")

        else:
            raise AssertionError(where)
_contents#
_fields#
_length = None#
_length_generator = None#
form_cls: awkward._typing.Final#
copy(contents=UNSET, fields=UNSET, length=UNSET, length_generator=UNSET, *, parameters=UNSET, backend=UNSET)#
classmethod simplified(contents, fields, length=None, length_generator=None, *, parameters=None, backend=None)#
to_tuple() awkward._typing.Self#
_form_with_key(getkey: awkward._typing.Callable[[awkward.contents.content.Content], str | None]) awkward.forms.recordform.RecordForm#
_form_with_key_path(path: awkward.forms.form.FormKeyPathT) awkward.forms.recordform.RecordForm#
_to_buffers(form: awkward.forms.form.Form, getkey: awkward._typing.Callable[[awkward.contents.content.Content, awkward.forms.form.Form, str], str], container: collections.abc.MutableMapping[str, awkward._nplikes.array_like.ArrayLike], backend: awkward._backends.backend.Backend, byteorder: str)#
_to_typetracer(forget_length: bool) awkward._typing.Self#
_touch_data(recursive: bool)#
_touch_shape(recursive: bool)#
property length: awkward._nplikes.shape.ShapeItem#
_repr(indent, pre, post)#
content(index_or_field: str | awkward._typing.SupportsIndex) awkward.contents.content.Content#
maybe_content(index_or_field) awkward.contents.content.Content#
_getitem_nothing() awkward.contents.content.Content#
_is_getitem_at_placeholder() bool#
_is_getitem_at_virtual() bool#
_getitem_at(where: awkward._nplikes.numpy_like.IndexType)#
_getitem_range(start: awkward._nplikes.numpy_like.IndexType, stop: awkward._nplikes.numpy_like.IndexType) awkward.contents.content.Content#
_getitem_field(where: str | awkward._typing.SupportsIndex, only_fields: tuple[str, Ellipsis] = ()) awkward.contents.content.Content#
_getitem_fields(where: list[str | awkward._typing.SupportsIndex], only_fields: tuple[str, Ellipsis] = ()) awkward.contents.content.Content#
_carry(carry: awkward.index.Index, allow_lazy: bool) awkward.contents.content.Content#
_getitem_next_jagged(slicestarts: awkward.index.Index, slicestops: awkward.index.Index, slicecontent: awkward.contents.content.Content, tail) awkward.contents.content.Content#
_getitem_next(head: awkward._slicing.SliceItem | tuple, tail: tuple[awkward._slicing.SliceItem, Ellipsis], advanced: awkward.index.Index | None) awkward.contents.content.Content#
_offsets_and_flattened(axis: int, depth: int) tuple[awkward.index.Index, awkward.contents.content.Content]#
_mergeable_next(other: awkward.contents.content.Content, mergebool: bool, mergecastable: awkward._typing.Literal[same_kind, equiv, family]) bool#
_mergemany(others: collections.abc.Sequence[awkward.contents.content.Content]) awkward.contents.content.Content#
_fill_none(value: awkward.contents.content.Content) awkward.contents.content.Content#
_local_index(axis, depth)#
_numbers_to_type(name, including_unknown)#
_is_unique(negaxis, starts, parents, offsets, outlength)#
abstract _unique(negaxis, starts, parents, offsets, outlength)#
abstract _argsort_next(negaxis, starts, shifts, parents, offsets, outlength, ascending, stable)#
_sort_next(negaxis, starts, parents, offsets, outlength, ascending, stable)#
_combinations(n, replacement, recordlookup, parameters, axis, depth)#
_reduce_next(reducer, negaxis, starts, shifts, parents, offsets, outlength, mask, keepdims, behavior)#
_validity_error(path)#
_nbytes_part()#
_pad_none(target, axis, depth, clip)#
_to_arrow(pyarrow: awkward._typing.Any, mask_node: awkward.contents.content.Content | None, validbytes: awkward.contents.content.Content | None, length: int, options: awkward.contents.content.ToArrowOptions)#
_to_cudf(cudf: awkward._typing.Any, mask: awkward.contents.content.Content | None, length: int)#
_to_backend_array(allow_missing, backend)#
_remove_structure(backend: awkward._backends.backend.Backend, options: awkward.contents.content.RemoveStructureOptions) list[awkward.contents.content.Content]#
_recursively_apply(action: awkward.contents.content.ImplementsApplyAction, depth: int, depth_context: collections.abc.Mapping[str, awkward._typing.Any] | None, lateral_context: collections.abc.Mapping[str, awkward._typing.Any] | None, options: awkward.contents.content.ApplyActionOptions) awkward.contents.content.Content | None#
_to_packed(recursive: bool = True) awkward._typing.Self#
_to_list(behavior, json_conversions)#
_to_backend(backend: awkward._backends.backend.Backend) awkward._typing.Self#
_materialize(type_) awkward._typing.Self#
property _is_all_materialized: bool#
property _is_any_materialized: bool#
_is_equal_to(other: awkward._typing.Self, index_dtype: bool, numpyarray: bool, all_parameters: bool) bool#