Skip to content

Commit

Permalink
Enable complex numbers when using DataArray.to_netcdf.
Browse files Browse the repository at this point in the history
  • Loading branch information
atrabattoni committed Jan 8, 2025
1 parent 571c8a8 commit 77926c7
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions xdas/virtual.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()])
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 77926c7

Please sign in to comment.