Skip to content

TypeError for time_bnds variable when calling Dataset.to_netcdf #7794

@sol1105

Description

@sol1105

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

import xarray as xr
import os

ds_url="https://github.com/roocs/mini-esgf-data/raw/master/test_data/badc/cmip5/data/cmip5/output1/MOHC/HadGEM2-ES/rcp85/day/land/day/r1i1p1/latest/mrsos/mrsos_day_HadGEM2-ES_rcp85_r1i1p1_20051201.nc"
ds_path="mrsos_day_HadGEM2-ES_rcp85_r1i1p1_20051201.nc"
if not os.path.isfile(ds_path): os.system(f"wget {ds_url}")

ds=xr.open_dataset(ds_path)

# With printing the values of the time_bnds variable, the to_netcdf-call later fails
# This is basically simulating the processing of the data
print(ds["time_bnds"].values)

chunked_ds_in = ds.chunk({"time":1})

chunked_ds_in.to_netcdf(path="input.nc", compute=True)

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.

Relevant log output

> TypeError: Invalid array type: <class 'cftime._cftime.Datetime360Day'>

I think the problem comes mainly from the change in
> xarray/core/common.py", line 1811, in _contains_cftime_datetimes
with xarray 2023.3.0

At least the problems disappears when I use the old implementation of `_contains_cftime_datetimes`.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy