-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeError for time_bnds variable when calling Dataset.to_netcdf #7794
Comments
Thanks for opening your first issue here at xarray! Be sure to follow the issue template! |
Why/where do you get a cftime._cftime.Datetime360Day ? It is deprecated according to cftime. |
The
This is the full traceback for reference:
|
Changing the def _contains_cftime_datetimes(array: Any) -> bool:
"""Check if a array inside a Variable contains cftime.datetime objects"""
if cftime is None:
return False
if array.dtype == np.dtype("O") and array.size > 0:
first_idx = (slice(0, 1),) * array.ndim # instead of (0,)
if isinstance(array, ExplicitlyIndexed):
first_idx = BasicIndexer(first_idx)
sample = array[first_idx]
return isinstance(np.asarray(sample).item(), cftime.datetime)
return False The only difference is that the index is not a scalar, but a slice of a single element. The error above shows that the |
There it is. xarray/xarray/core/indexing.py Lines 685 to 690 in 90e00f0
import numpy as np
np.isscalar(1) # True, as expected
import cftime
c = cftime.datetime(2000, 1, 1, calendar='360_day') # Calendar doesn't matter, this is an example.
np.isscalar(c) # False, as not expected We either need to fix |
I don't think the fix would be in numpy. >>> np.ndim(c)
0 |
@aulemahal @huard Thank you very much for addressing this issue! |
What happened?
In the workflow I load the dataset (clisops), remap it (xesmf), chunk it according to the available memory, then write it to disk (clisops). I encounter however a TypeError when writing the Dataset to disk, since
xarray>=2023.3.0
.What did you expect to happen?
The Dataset to be written to disk.
Minimal Complete Verifiable Example
MVCE confirmation
Relevant log output
Anything else we need to know?
No response
Environment
INSTALLED VERSIONS
commit: None
python: 3.10.10 | packaged by conda-forge | (main, Mar 24 2023, 20:08:06) [GCC 11.3.0]
python-bits: 64
OS: Linux
OS-release: 5.4.0-147-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: ('en_US', 'UTF-8')
libhdf5: 1.14.0
libnetcdf: 4.9.2
xarray: 2023.4.2
pandas: 1.5.3
numpy: 1.23.5
scipy: 1.10.1
netCDF4: 1.6.3
pydap: None
h5netcdf: None
h5py: None
Nio: None
zarr: None
cftime: 1.6.2
nc_time_axis: None
PseudoNetCDF: None
iris: None
bottleneck: 1.3.7
dask: 2023.3.2
distributed: 2023.3.2
matplotlib: 3.7.1
cartopy: None
seaborn: None
numbagg: None
fsspec: 2023.3.0
cupy: None
pint: None
sparse: 0.14.0
flox: None
numpy_groupies: None
setuptools: 67.6.1
pip: 23.0.1
conda: None
pytest: 7.2.2
mypy: None
IPython: 8.12.0
sphinx: 6.1.3
The text was updated successfully, but these errors were encountered: