From 77926c75111fe9796df134c4b13400cd6e6ed7d1 Mon Sep 17 00:00:00 2001 From: Alister Trabattoni Date: Wed, 8 Jan 2025 16:53:10 +0100 Subject: [PATCH] Enable complex numbers when using DataArray.to_netcdf. --- xdas/virtual.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/xdas/virtual.py b/xdas/virtual.py index 7b854f2..e5ce9aa 100644 --- a/xdas/virtual.py +++ b/xdas/virtual.py @@ -251,9 +251,7 @@ def __array__(self, dtype=None): with TemporaryDirectory() as tmpdirname: fname = os.path.join(tmpdirname, "vds.h5") with h5py.File(fname, "w") as file: - dataset = file.create_virtual_dataset( - "__values__", self._layout, fillvalue=np.nan - ) + dataset = self.to_dataset(file, "__values__") with h5py.File(fname, "r") as file: dataset = file["__values__"] out = np.asarray(dataset[self._sel.get_indexer()]) @@ -288,6 +286,8 @@ def to_dataset(self, file_or_group, name): fillvalue = np.iinfo(self.dtype).min elif np.issubdtype(self.dtype, np.floating): fillvalue = np.nan + elif np.issubdtype(self.dtype, np.complexfloating): + fillvalue = np.nan + 1j * np.nan else: fillvalue = None return file_or_group.create_virtual_dataset(