Closed
Description
What happened?
Using xarray.open_dataset. Trying to read a Netcdf dataset with generic time coordinates, not CF, with time:units = "seconds". Trying to apply the conversion "time_unit='us'" as directed by a warning message.
- Got an invalid "SerializationWarning" message.
- Argument "time_unit='us'" seems to be ignored. Time is converted to nanosecs rather than microsecs.
What did you expect to happen?
- After input, time coordinates should be microsecs rather than nanosecs.
- Clean execution with no warning message.
Minimal Complete Verifiable Example
#!/usr/bin/env python3
import xarray as xr
coder = xr.coders.CFDatetimeCoder (use_cftime=False, time_unit='us')
IN = xr.open_dataset ('xtime.nc', decode_timedelta=coder)
print (IN)
# See below for source code to generate the simple "xtime.nc" test file.
MVCE confirmation
- Minimal example — the example is as focused as reasonably possible to demonstrate the underlying issue in xarray.
- Complete example — the example is self-contained, including all data and the text of any traceback.
- Verifiable example — the example copy & pastes into an IPython prompt or Binder notebook, returning the result.
- New issue — a search of GitHub Issues suggests this is not a duplicate.
- Recent environment — the issue occurs with the latest version of xarray and its dependencies.
Relevant log output
(test_env) > ./demo.time.2.py
/home/xxxxxx/demo.time.2.py:4: SerializationWarning: Can't decode floating point timedelta to 's' without precision loss, decoding to 'us' instead. To silence this warning use time_unit='us' in call to decoding function.
IN = xr.open_dataset ('xtime.nc', decode_timedelta=coder)
<xarray.Dataset> Size: 40B
Dimensions: (time: 5)
Coordinates:
* time (time) timedelta64[ns] 40B 00:00:48.561388 ... 00:01:47.403320
Data variables:
*empty*
Anything else we need to know?
Source code for xtime.nc:
netcdf xtime {
dimensions:
time = 5 ;
variables:
float time(time) ;
time:units = "seconds" ;
data:
time = 48.56139, 63.27169, 77.98219, 92.6929, 107.4033 ;
}
Generate the actual test file using this command:
ncgen -o xtime.nc xtime.txt
Environment
INSTALLED VERSIONS
------------------
commit: None
python: 3.13.1 | packaged by conda-forge | (main, Jan 13 2025, 09:53:10) [GCC 13.3.0]
python-bits: 64
OS: Linux
OS-release: 4.18.0-553.36.1.el8_10.x86_64
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: C
LOCALE: ('C', 'UTF-8')
libhdf5: 1.14.4
libnetcdf: 4.9.2
xarray: 2025.1.2
pandas: 2.2.3
numpy: 2.2.2
scipy: 1.15.1
netCDF4: 1.7.2
pydap: None
h5netcdf: None
h5py: None
zarr: None
cftime: 1.6.4
nc_time_axis: None
iris: None
bottleneck: None
dask: 2025.1.0
distributed: 2025.1.0
matplotlib: 3.10.0
cartopy: 0.24.0
seaborn: None
numbagg: None
fsspec: 2025.2.0
cupy: None
pint: 0.24.4
sparse: None
flox: None
numpy_groupies: None
setuptools: None
pip: 25.0
conda: None
pytest: None
mypy: None
IPython: None
sphinx: None