Skip to content

Commit

Permalink
Skip daily SPI tests with ML on older numpy to avoid dtype-related CI…
Browse files Browse the repository at this point in the history
… errors (#1862)

### What kind of change does this PR introduce?

* Skip SPI tests in `test_indices` when `freq='D'` and `method='ML'`. On
numpy < 2, input float32 data are promoted to float64 somewhere along
the computation, which they stay float32 on numpy>=2. In order to keep
stricter expected values, we skip these tests on older numpy, rather
then increasing the tolerance.

### Does this PR introduce a breaking change?
No
  • Loading branch information
Zeitsperre committed Aug 1, 2024
2 parents e36a41d + d7f8487 commit 9ce9a50
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions tests/test_indices.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import pytest
import xarray as xr
from cf_xarray import __version__ as __cfxr_version__
from numpy import __version__ as __numpy_version__
from packaging.version import Version
from pint import __version__ as __pint_version__

Expand Down Expand Up @@ -708,6 +709,13 @@ def test_standardized_precipitation_index(
def test_standardized_precipitation_evapotranspiration_index(
self, open_dataset, freq, window, dist, method, values, diff_tol
):
if (
method == "ML"
and freq == "D"
and Version(__numpy_version__) < Version("2.0.0")
):
pytest.skip("Skipping SPI/ML/D on older numpy")

ds = (
open_dataset("sdba/CanESM2_1950-2100.nc")
.isel(location=1)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_sdba/test_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def test_annual_cycle(self, open_dataset):
np.testing.assert_allclose(
[amp.values, relamp.values, phase.values],
[16.74645996, 5.802083, 167],
rtol=1e-6,
rtol=1e-5,
)
with pytest.raises(
ValueError,
Expand Down

0 comments on commit 9ce9a50

Please sign in to comment.