ak._v2.ak_from_buffers.from_buffers

Defined in awkward._v2.operations.convert.ak_from_buffers on line 12.

ak._v2.ak_from_buffers.from_buffers(form, length, container, buffer_key='{form_key}-{attribute}', nplike=numpy, highlevel=True, behavior=None)
Parameters
  • form (ak.forms.Form or str/dict equivalent) – The form of the Awkward Array to reconstitute from named buffers.

  • length (int) – Length of the array. (The output of this function is always single-partition.)

  • container (Mapping, such as dict) – The str → Python buffers that represent the decomposed Awkward Array. This container is only assumed to have a __getitem__ method that accepts strings as keys.

  • buffer_key (str or callable) – Python format string containing "{form_key}" and/or "{attribute}" or a function that takes these as keyword arguments and returns a string to use as a key for a buffer in the container.

  • nplike (ak.nplike.NumpyLike) – Library to use to generate values that are put into the new array. The default, ak.nplike.Numpy, makes NumPy arrays, which are in main memory (e.g. not GPU). If all the values in container have the same nplike as this, they won’t be copied.

  • highlevel (bool) – If True, return an ak.Array; otherwise, return a low-level ak.layout.Content subclass.

  • behavior (None or dict) – Custom ak.behavior for the output array, if high-level.

Reconstitutes an Awkward Array from a Form, length, and a collection of memory buffers, so that data can be losslessly read from file formats and storage devices that only map names to binary blobs (such as a filesystem directory).

The first three arguments of this function are the return values of ak.to_buffers, so a full round-trip is

>>> reconstituted = ak.from_buffers(*ak.to_buffers(original))

The container argument lets you specify your own Mapping, which might be an interface to some storage format or device (e.g. h5py). It’s okay if the container dropped NumPy’s dtype and shape information, leaving raw bytes, since dtype and shape can be reconstituted from the ak.forms.NumpyForm.

The buffer_key should be the same as the one used in ak.to_buffers.

See ak.to_buffers for examples.