ak.contents.IndexedArray#

Defined in awkward.contents.indexedarray on line 57.

class ak.contents.IndexedArray(index, content, *, parameters=None)#

IndexedArray is a general-purpose tool for lazily changing the order of and/or duplicating some content with a np.take over the integer buffer index.

It has many uses:

  • representing a lazily applied slice.

  • simulating pointers into another collection.

  • emulating the dictionary encoding of Apache Arrow and Parquet.

If the __array__ parameter is "categorical", the contents must be unique. Some operations are optimized (for instance, == only compares index integers) and the array can be converted to and from Arrow/Parquet’s dictionary encoding.

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

class IndexedArray(Content):
def __init__(self, index, content):

assert isinstance(index, (Index32, IndexU32, Index64)) assert isinstance(content, Content) for x in index:

assert 0 <= x < len(content) # index[i] must not be negative

self.index = index self.content = content

def __len__(self):

return len(self.index)

def __getitem__(self, where):
if isinstance(where, int):
if where < 0:

where += len(self)

assert 0 <= where < len(self) return self.content[self.index[where]]

elif isinstance(where, slice) and where.step is None:
return IndexedArray(

self.index[where.start : where.stop], self.content

)

elif isinstance(where, str):

return IndexedArray(self.index, self.content[where])

else:

raise AssertionError(where)

property index#
form_cls: awkward._typing.Final#
copy(index=UNSET, content=UNSET, *, parameters=UNSET)#
classmethod simplified(index, content, *, parameters=None)#
property length: awkward._nplikes.shape.ShapeItem#
to_IndexedOptionArray64() awkward.contents.indexedoptionarray.IndexedOptionArray#
mask_as_bool(valid_when: bool = True) awkward._nplikes.array_like.ArrayLike#
project(mask=None)#