Skip to content

Problems with xarray opening datasets with timedeltas with climada 6.1.0 #1196

@ValentinGebhart

Description

@ValentinGebhart

Describe the bug
Creating an environment with climada 6.1.0 installs xarray 2025.06 which has a bug when decoding timdeltas. See this issue: pydata/xarray#10468. The bug is resolved in xarray 2025.07, see https://docs.xarray.dev/en/stable/whats-new.html#whats-new

This bug leads to breaking pipelines when using forecast data which make use of timedeltas, e.g.,

  • in the copernicus module (using an envirnoment with climada 6.1.0 results in the error) and
  • in downloading meteoswiss OGD data by @Evelyn-M (this was the error, right?)

To Reproduce
Simple example to reproduce

import xarray
import pandas as pd

ds = xarray.Dataset({'lead_time': pd.timedelta_range('0h', '12h', freq='h', unit='s')})
ds.to_netcdf('on-disk2.nc', format='NETCDF4')
xarray.open_dataset('on-disk2.nc')

The above code works if I create an environment with

conda create -n copernicus-dev-mode python=3.11 pip geopandas xarray

which installs xarray2025.12, but results in an error with

conda create -n copernicus-dev-mode python=3.11 pip geopandas climada

which installs xarray2025.06:

ValueError: Failed to decode variable 'lead_time': failed to prevent overwriting existing key dtype in attrs on variable 'lead_time'. This is probably an encoding field used by xarray to describe how a variable is serialized. To proceed, remove this key from the variable's attributes manually.

Question
Is this something we could fix easily, e.g., with a bug release that requires xarray 2025.07? Or just wait until a new release with a climada version that requires later xarray versions?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions