What happened?
Running the example code in the documentation with a DataTree appears to be broken. The data is read back in encoded form rather than turned automatically into a complex number.
What did you expect to happen?
The datatree's datasets should respect auto_complex and read back the encoded data as complex numbers.
Minimal Complete Verifiable Example
import xarray as xr
import numpy as np
data = np.array([[1 + 2j, 3 + 4j], [5 + 6j, 7 + 8j]])
dt2 = xr.DataTree(
xr.Dataset({'data': xr.DataArray(
data,
dims=["x", "y"],
coords={"x": ["a", "b"], "y": [1, 2]},
name="complex_nums",
)})
)
# write the data to disk
dt2.to_netcdf("complex_nums_nc4.nc", engine="netcdf4", auto_complex=True)
# read the file back into memory
with xr.open_datatree(
"complex_nums_nc4.nc", engine="netcdf4", auto_complex=True
) as dt_nc4:
print(dt_nc4['data'].dtype)
# prints: {'names': ['r', 'i'], 'formats': ['<f8', '<f8'], 'offsets': [0, 8], 'itemsize': 16, 'aligned': True}
MVCE confirmation
Relevant log output
Anything else we need to know?
No response
Environment
Details
What happened?
Running the example code in the documentation with a
DataTreeappears to be broken. The data is read back in encoded form rather than turned automatically into a complex number.What did you expect to happen?
The datatree's datasets should respect
auto_complexand read back the encoded data as complex numbers.Minimal Complete Verifiable Example
MVCE confirmation
Relevant log output
Anything else we need to know?
No response
Environment
Details