|
27 | 27 | import pandas as pd |
28 | 28 | import pytest |
29 | 29 | import xarray as xr |
| 30 | +from packaging.version import Version |
30 | 31 | from scipy.sparse import csr_matrix |
31 | 32 |
|
32 | 33 | from climada.hazard.base import Hazard |
33 | 34 | from climada.hazard.centroids.centr import Centroids |
34 | 35 | from climada.hazard.forecast import HazardForecast |
35 | 36 | from climada.hazard.test.test_base import hazard_kwargs |
36 | 37 |
|
| 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 | + |
37 | 45 |
|
38 | 46 | @pytest.fixture |
39 | 47 | def haz_kwargs(): |
@@ -193,6 +201,7 @@ def forecast_netcdf_file(self, tmp_path_factory): |
193 | 201 | "crs": crs, |
194 | 202 | } |
195 | 203 |
|
| 204 | + @xarray_leadtime |
196 | 205 | def test_from_xarray_raster_basic(self, forecast_netcdf_file): |
197 | 206 | """Test basic loading of forecast hazard from xarray""" |
198 | 207 | haz_fc = HazardForecast.from_xarray_raster( |
@@ -231,6 +240,7 @@ def test_from_xarray_raster_basic(self, forecast_netcdf_file): |
231 | 240 | assert len(haz_fc.centroids.lat) == expected_n_centroids |
232 | 241 | assert len(haz_fc.centroids.lon) == expected_n_centroids |
233 | 242 |
|
| 243 | + @xarray_leadtime |
234 | 244 | def test_from_xarray_raster_event_names(self, forecast_netcdf_file): |
235 | 245 | """Test that event names are auto-generated from lead_time and member""" |
236 | 246 | haz_fc = HazardForecast.from_xarray_raster( |
@@ -258,6 +268,7 @@ def test_from_xarray_raster_event_names(self, forecast_netcdf_file): |
258 | 268 | ] |
259 | 269 | npt.assert_array_equal(haz_fc.event_name, event_names_expected) |
260 | 270 |
|
| 271 | + @xarray_leadtime |
261 | 272 | def test_from_xarray_raster_dates(self, forecast_netcdf_file): |
262 | 273 | """Test that dates are set to 0 for forecast events""" |
263 | 274 | haz_fc = HazardForecast.from_xarray_raster( |
|
0 commit comments