ak.contents.RecordArray#

Defined in awkward.contents.recordarray on line 63.

class ak.contents.RecordArray(self, contents, fields, length=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)
ak.contents.RecordArray.fields#
ak.contents.RecordArray.copy(self, contents=UNSET, fields=UNSET, length=UNSET, *, parameters=UNSET, backend=UNSET)#
ak.contents.RecordArray.__copy__(self)#
ak.contents.RecordArray.__deepcopy__(self, memo)#
ak.contents.RecordArray.simplified(cls, contents, fields, length=None, *, parameters=None, backend=None)#
ak.contents.RecordArray.is_tuple#
ak.contents.RecordArray.to_tuple(self)#
ak.contents.RecordArray._form_with_key(self, getkey)#
ak.contents.RecordArray._to_buffers(self, form, getkey, container, backend, byteorder)#
ak.contents.RecordArray._to_typetracer(self, forget_length)#
ak.contents.RecordArray._touch_data(self, recursive)#
ak.contents.RecordArray._touch_shape(self, recursive)#
ak.contents.RecordArray.length#
ak.contents.RecordArray.__repr__(self)#
ak.contents.RecordArray._repr(self, indent, pre, post)#
ak.contents.RecordArray.content(self, index_or_field)#
ak.contents.RecordArray.maybe_content(self, index_or_field)#
ak.contents.RecordArray._getitem_nothing(self)#
ak.contents.RecordArray._is_getitem_at_placeholder(self)#
ak.contents.RecordArray._getitem_at(self, where)#
ak.contents.RecordArray._getitem_range(self, start, stop)#
ak.contents.RecordArray._getitem_field(self, where, only_fields=())#
ak.contents.RecordArray._getitem_fields(self, where, only_fields=())#
ak.contents.RecordArray._carry(self, carry, allow_lazy)#
ak.contents.RecordArray._getitem_next_jagged(self, slicestarts, slicestops, slicecontent, tail)#
ak.contents.RecordArray._getitem_next(self, head, tail, advanced)#
ak.contents.RecordArray._offsets_and_flattened(self, axis, depth)#
ak.contents.RecordArray._mergeable_next(self, other, mergebool)#
ak.contents.RecordArray._mergemany(self, others)#
ak.contents.RecordArray._fill_none(self, value)#
ak.contents.RecordArray._local_index(self, axis, depth)#
ak.contents.RecordArray._numbers_to_type(self, name, including_unknown)#
ak.contents.RecordArray._is_unique(self, negaxis, starts, parents, outlength)#
ak.contents.RecordArray._unique(self, negaxis, starts, parents, outlength)#
ak.contents.RecordArray._argsort_next(self, negaxis, starts, shifts, parents, outlength, ascending, stable)#
ak.contents.RecordArray._sort_next(self, negaxis, starts, parents, outlength, ascending, stable)#
ak.contents.RecordArray._combinations(self, n, replacement, recordlookup, parameters, axis, depth)#
ak.contents.RecordArray._reduce_next(self, reducer, negaxis, starts, shifts, parents, outlength, mask, keepdims, behavior)#
ak.contents.RecordArray._validity_error(self, path)#
ak.contents.RecordArray._nbytes_part(self)#
ak.contents.RecordArray._pad_none(self, target, axis, depth, clip)#
ak.contents.RecordArray._to_arrow(self, pyarrow, mask_node, validbytes, length, options)#
ak.contents.RecordArray._to_cudf(self, cudf, mask, length)#
ak.contents.RecordArray._to_backend_array(self, allow_missing, backend)#
ak.contents.RecordArray._remove_structure(self, backend, options)#
ak.contents.RecordArray._recursively_apply(self, action, depth, depth_context, lateral_context, options)#
ak.contents.RecordArray.to_packed(self, recursive=True)#
ak.contents.RecordArray._to_list(self, behavior, json_conversions)#
ak.contents.RecordArray._to_backend(self, backend)#
ak.contents.RecordArray._is_equal_to(self, other, index_dtype, numpyarray, all_parameters)#