Open
Description
What happened?
I have been given a netCDF file (I think it's netCDF3) which when I open it does not decode the time variable in the way I expected it to. The time coordinate created is a numpy object array
What did you expect to happen?
I expected it to automatically create a coordinate backed by a CFTimeIndex
object, not a CFTimeIndex
object wrapped inside another array type.
Minimal Complete Verifiable Example
The original problematic file is 455MB (I can share it if necessary), but I can create a small netCDF file that displays the same issue.
import cftime
time_values = [cftime.DatetimeNoLeap(347, 2, 1, 0, 0, 0, 0, has_year_zero=True)]
time_ds = xr.Dataset(coords={'time': (['time'], time_values)})
print(time_ds)
time_ds.to_netcdf('time_mwe.nc')
<xarray.Dataset>
Dimensions: (time: 1)
Coordinates:
* time (time) object 0347-02-01 00:00:00
Data variables:
*empty*
ds = xr.open_dataset('time_mwe.nc', engine='netcdf4', decode_times=True, use_cftime=True)
print(ds)
<xarray.Dataset>
Dimensions: (time: 1)
Coordinates:
* time (time) object 0347-02-01 00:00:00
Data variables:
*empty*
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
No response
Anything else we need to know?
No response
Environment
cftime 1.6.2
netcdf4 1.6.4
xarray 2023.8.0