Commit 0669e0c6 authored by PIOLLE's avatar PIOLLE
Browse files

fixed dtype detection

parent 340c5d31
......@@ -195,11 +195,11 @@ def io_encoding_dtype(data: xr.DataArray) -> np.dtype:
if fillv is None:
return data.dtype
if np.dtype(fillv) != data.dtype:
if np.dtype(type(fillv)) != data.dtype:
# no scaling was applied but xarray may have changed the dtype for
# instance if fill values were replaced with NaN. Returns the
# intended scientific dtype indicated by the _FillValue attr.
return np.dtype(fillv)
return np.dtype(type(fillv))
dtype = np.dtype(type(scale))
......@@ -2002,7 +2002,8 @@ class Dataset(ABC):
dtype = np.dtype(encoding.get(C_DTYPE, svar.dtype))
if np.issubdtype(dtype, np.datetime64):
if (np.issubdtype(dtype, np.datetime64)
or np.issubdtype(dtype, np.timedelta64)):
dtype = np.dtype(np.float64)
encoding['dtype'] = dtype
......@@ -2017,7 +2018,8 @@ class Dataset(ABC):
internals.Encoding.IO_FILLVALUE, default_fv)
fillv = self._xr_fillvalue(svar, default_fv)
if np.issubdtype(type(fillv), np.datetime64):
if (np.issubdtype(dtype, np.datetime64)
or np.issubdtype(dtype, np.timedelta64)):
# xarray might change automatically the _FillValue encoding
# to NaT, then overwriting the previously encode value
fillv = default_fv
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment