Skip to content

Commit

Permalink
Handle exceptionally rare linear algebra error (#2015)
Browse files Browse the repository at this point in the history
### What kind of change does this PR introduce?

* Adds handling for a rare but mathematically possible error that has
happened at least once in `xclim`

### Does this PR introduce a breaking change?

No.
  • Loading branch information
Zeitsperre authored Dec 10, 2024
2 parents 2195f08 + 3060439 commit c1bde75
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Internal changes
* The `numpydoc` linting tool has been added to the development dependencies, linting checks, and the `pre-commit` configuration. (:pull:`1988`).
* `xclim` now uses a `src` layout for the codebase. Structure-dependent functions, documentation, and build commands have been adapted to reflect these changes. (:pull:`1971`).
* Added a more robust `yamllint` configuration to ensure that all YAML files are linted consistently. (:pull:`1971`).
* Addressed a very rare singular matrix error that can happen in ``test_loess_smoothing_nan``. (:pull:`2015`).

CI changes
^^^^^^^^^^
Expand Down
11 changes: 10 additions & 1 deletion tests/test_sdba/test_loess.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

import logging

import numpy as np
import pandas as pd
import pytest
Expand Down Expand Up @@ -84,4 +86,11 @@ def test_loess_smoothing_nan(use_dask):

assert out.dims == da.dims
# check that the output is all nan on the axis with nan in the input
assert np.isnan(out.values[0, 0]).all()
try:
assert np.isnan(out.values[0, 0]).all()
except np.linalg.LinAlgError:
msg = (
"This has roughly a 1/50,000,000 chance of occurring. Buy a lottery ticket!"
)
logging.error(msg)
pass

0 comments on commit c1bde75

Please sign in to comment.