ak.contents.ListOffsetArray#
Defined in awkward.contents.listoffsetarray on line 56.
- class ak.contents.ListOffsetArray(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 contiguouscontent. It is subdivided into lists according to anoffsetsbuffer, which specifies the starting and stopping index of each list.The
offsetsmust have at least length 1 (corresponding to an empty array), but it need not start with0or include all of thecontent. Just asak.contents.RegularArraycan have unreachablecontentif it is not an integer multiple ofsize, a ListOffsetArray can have unreachable content before the start of the first list and after the end of the last list.Like
ak.contents.RegularArrayandak.contents.ListArray, a ListOffsetArray can represent strings if its__array__parameter is"string"(UTF-8 assumed) or"bytestring"(no encoding assumed) and it contains anak.contents.NumpyArrayofdtype=np.uint8whose__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)
- property offsets: awkward.index.Index#
- form_cls: awkward._typing.Final#
- copy(offsets=UNSET, content=UNSET, *, parameters=UNSET)#
- classmethod simplified(offsets, content, *, parameters=None)#
- property starts: awkward.index.Index#
- property stops#
- property length: awkward._nplikes.shape.ShapeItem#
- to_ListOffsetArray64(start_at_zero: bool = False) ListOffsetArray#
- to_RegularArray()#