fields.buffers.core.HDF5Buffer.replace_dataset#

HDF5Buffer.replace_dataset(shape: tuple | None = None, dtype: Any | None = None, data: ndarray | list | unyt_array | None = None, *, units: str | Unit | None = None, **kwargs) HDF5Buffer[source]#

Replace the current HDF5 dataset with a newly created one.

This method deletes and recreates the dataset at the same internal HDF5 path (self.name) with optionally modified shape, dtype, data, and units. It is useful for performing operations like reshape, astype, or structural updates in-place, without requiring the caller to manage HDF5 file I/O manually.

Parameters:
  • shape (tuple of int, optional) – New shape for the dataset. If not provided, uses the current shape.

  • dtype (data-type, optional) – Desired data type for the new dataset. Defaults to the current dtype.

  • data (array-like, optional) – Data to populate the new dataset. If not provided, the current buffer data is reused.

  • units (str or unyt.Unit, optional) – Units to assign to the new dataset. If not provided, preserves the current units.

  • **kwargs – Additional keyword arguments passed to create_dataset(), such as compression options.

Returns:

The same buffer instance, now referencing the newly created dataset.

Return type:

HDF5Buffer

Notes

  • The underlying HDF5 file must be writable.

  • This will delete the existing dataset at self.name.

  • Units are preserved by default unless explicitly overridden.