fields.buffers.base.BufferBase.from_array#

abstract classmethod BufferBase.from_array(obj: Any, *args, dtype: Any | None = None, **kwargs) BufferBase[source]#

Attempt to construct a new buffer instance from an array-like object.

This method is the canonical entry point for converting arbitrary array-like inputs into a buffer of this type. It behaves similarly to a cast operation, and will coerce the input as needed to match the expected backend format (e.g., ndarray, class:~unyt.unyt_array, etc.).

The method should be overridden in subclasses to handle type conversion, unit attachment, memory layout, or any other backend-specific behavior.

Parameters:
  • obj (array-like) – Input data to be wrapped. This can be any object that is compatible with the backend’s array casting rules—such as lists, tuples, NumPy arrays, unyt arrays, or backend-native types (e.g., HDF5 datasets). The input will be coerced into a backend-compatible array before being wrapped in a buffer instance. If coercion fails, a TypeError will be raised.

  • dtype (data-type, optional) – Desired data type of the resulting array. If not specified, the type is inferred from obj.

  • *args

    Additional arguments to customize the construction. These may include:

    • units for unit-aware buffers

    • order, copy, or device for backend-specific configuration

    • Any arguments accepted by the backend constructor

  • **kwargs

    Additional arguments to customize the construction. These may include:

    • units for unit-aware buffers

    • order, copy, or device for backend-specific configuration

    • Any arguments accepted by the backend constructor

Returns:

A new buffer instance wrapping the coerced array.

Return type:

BufferBase

Raises:

TypeError – If the input cannot be coerced into a valid array for this backend.