ak.layout.EmptyArray — Awkward Array documentation

# ak.layout.EmptyArray

An EmptyArray is used whenever an array’s type is not known because it is empty (such as data from ak.ArrayBuilder without enough sample points to resolve the type).

EmptyArray has no equivalent in Apache Arrow.

Below is a simplified implementation of an EmptyArray class in pure Python that exhaustively checks validity in its constructor (see ak.is_valid) and can generate random valid arrays. The `random_number()` function returns a random float and the `random_length(minlen)` function returns a random int that is at least `minlen`. The `RawArray` class represents simple, one-dimensional data.

    class EmptyArray(Content):
        def __init__(self):
            pass

        @staticmethod
        def random(minlen, choices):
            assert minlen == 0
            return EmptyArray()

        def __len__(self):
            return 0

        def __getitem__(self, where):
            if isinstance(where, int):
                assert False
            elif isinstance(where, slice) and where.step is None:
                return EmptyArray()
            elif isinstance(where, str):
                raise ValueError("field " + repr(where) + " not found")
            else:
                raise AssertionError(where)

        def __repr__(self):
            return "EmptyArray()"

        def xml(self, indent="", pre="", post=""):
            return indent + pre + "<EmptyArray/>" + post

Here is an example:

    EmptyArray()

    <EmptyArray/>

which represents the following logical data.

    []

In addition to the properties and methods described in ak.layout.Content, an EmptyArray has the following.

## ak.layout.EmptyArray.__init__

ak.layout.EmptyArray.__init__(identities=None, parameters=None)

## ak.layout.EmptyArray.toNumpyArray

ak.layout.EmptyArray.toNumpyArray()

Converts this EmptyArray into a ak.layout.NumpyArray with 64-bit floating-point type.

## ak.layout.EmptyArray.simplify

ak.layout.EmptyArray.simplify()

Pass-through; returns the original array.