When using dask-backed datasets/arrays it does not seem possible to use the 'h5netcdf' engine to write to disk:
import xarray as xr
ds = xr.Dataset({'a': ('x', [1, 2])}, {'x': [3, 4]}).chunk()
ds.to_netcdf("test.h5", engine='h5netcdf')
results in the error:
...
h5py/h5a.pyx in h5py.h5a.open()
KeyError: "Can't open attribute (can't locate attribute: 'dask')"
Not sure if this is a xarray or h5netcdf issue - or some inherent limitation in which case apologies!