Skip to content

Commit 9685a81

Browse files
committed
Skip tests for incompatible xarray versions
1 parent b5e7d7a commit 9685a81

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

climada/hazard/test/test_forecast.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,21 @@
2727
import pandas as pd
2828
import pytest
2929
import xarray as xr
30+
from packaging.version import Version
3031
from scipy.sparse import csr_matrix
3132

3233
from climada.hazard.base import Hazard
3334
from climada.hazard.centroids.centr import Centroids
3435
from climada.hazard.forecast import HazardForecast
3536
from climada.hazard.test.test_base import hazard_kwargs
3637

38+
# See https://docs.xarray.dev/en/stable/whats-new.html#id80
39+
xarray_leadtime = pytest.mark.skipif(
40+
(Version(xr.__version__) < Version("2025.07.0"))
41+
and (Version(xr.__version__) >= Version("2025.04.0")),
42+
reason="xarray timedelta bug",
43+
)
44+
3745

3846
@pytest.fixture
3947
def haz_kwargs():
@@ -193,6 +201,7 @@ def forecast_netcdf_file(self, tmp_path_factory):
193201
"crs": crs,
194202
}
195203

204+
@xarray_leadtime
196205
def test_from_xarray_raster_basic(self, forecast_netcdf_file):
197206
"""Test basic loading of forecast hazard from xarray"""
198207
haz_fc = HazardForecast.from_xarray_raster(
@@ -231,6 +240,7 @@ def test_from_xarray_raster_basic(self, forecast_netcdf_file):
231240
assert len(haz_fc.centroids.lat) == expected_n_centroids
232241
assert len(haz_fc.centroids.lon) == expected_n_centroids
233242

243+
@xarray_leadtime
234244
def test_from_xarray_raster_event_names(self, forecast_netcdf_file):
235245
"""Test that event names are auto-generated from lead_time and member"""
236246
haz_fc = HazardForecast.from_xarray_raster(
@@ -258,6 +268,7 @@ def test_from_xarray_raster_event_names(self, forecast_netcdf_file):
258268
]
259269
npt.assert_array_equal(haz_fc.event_name, event_names_expected)
260270

271+
@xarray_leadtime
261272
def test_from_xarray_raster_dates(self, forecast_netcdf_file):
262273
"""Test that dates are set to 0 for forecast events"""
263274
haz_fc = HazardForecast.from_xarray_raster(

0 commit comments

Comments
 (0)