Skip to content

Commit 2011405

Browse files
raspstephanWeatherbench2 authors
authored andcommitted
Manually set timedelta64 encoding to int32 before saving to netCDF.
This is required since xarray=2025.06.1 will not automatically cast int64 to int32 any more PiperOrigin-RevId: 775606362
1 parent 8074978 commit 2011405

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

weatherbench2/evaluation.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,10 @@ def _get_output_path(
382382

383383
def _to_netcdf(dataset: xr.Dataset, filename: str) -> None:
384384
with fsspec.open(filename, 'wb', auto_mkdir=True) as f:
385+
for coord in dataset.coords:
386+
if dataset[coord].dtype == 'timedelta64[ns]':
387+
# Make sure to also override all other existing encodings.
388+
dataset[coord].encoding = {'dtype': 'int32'}
385389
f.write(dataset.to_netcdf())
386390

387391

0 commit comments

Comments
 (0)