fields.buffers.core.HDF5Buffer.from_array#
- classmethod HDF5Buffer.from_array(obj: Any, file: str | Path | File | None = None, path: str | None = None, *args, dtype: Any | None = None, units: Unit | str | None = None, **kwargs) HDF5Buffer [source]#
Construct an HDF5-backed buffer from an array-like object or existing HDF5 dataset.
This method wraps either:
an existing h5py.Dataset, or
arbitrary in-memory data by creating a new dataset in the specified HDF5 file.
- Parameters:
obj (
array-like
orDataset
) – The data to store. If already ah5py.Dataset
, it is wrapped directly. Otherwise, it is coerced to a unyt_array and stored in a new dataset.file (
str
,Path
, orFile
, optional) – Path to the HDF5 file or an open file object. Required if obj is not already a dataset.path (
str
, optional) – Internal path for the new dataset in the HDF5 file. Required if obj is not already a dataset.dtype (
data-type
, optional) – Desired data type of the dataset. Defaults to the dtype inferred from obj.units (
str
orUnit
, optional) – Units to attach to the dataset. If obj already has units, this overrides them.overwrite (
bool
, defaultFalse
) – If True, any existing dataset at the given path will be deleted and replaced.**kwargs – Additional keyword arguments forwarded to
create_dataset()
.
- Returns:
A lazily-loaded buffer backed by an HDF5 dataset.
- Return type:
- Raises:
ValueError – If file or path is not specified when required.
TypeError – If input types are not supported or invalid.
See also
HDF5Buffer.create_dataset
Core method used for new dataset creation.
buffer_from_array
Registry-based entry point to buffer resolution.