From 4e6608d4fa6d459878e4f70d7c11fb002a8603db Mon Sep 17 00:00:00 2001 From: SarahG-579462 Date: Wed, 11 Dec 2024 18:54:13 +0000 Subject: [PATCH 1/4] Proper fix for loess linalg error - non-random tests --- tests/test_sdba/test_loess.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/tests/test_sdba/test_loess.py b/tests/test_sdba/test_loess.py index fb802f3fa..99281b740 100644 --- a/tests/test_sdba/test_loess.py +++ b/tests/test_sdba/test_loess.py @@ -74,7 +74,20 @@ def test_loess_smoothing(use_dask, open_dataset): @pytest.mark.parametrize("use_dask", [True, False]) def test_loess_smoothing_nan(use_dask): # create data with one axis full of nan - data = np.random.randn(2, 2, 10) + # (random array taken from np.random.randn) + data = np.array( + [ + -0.993, -0.980, -0.452, -0.076, 0.447, + 0.389, 2.408, 0.966, -0.793, 0.090, + -0.173, 1.713, -1.579, 0.454, -0.272, + -0.005, -0.926, -2.022, -1.661, -0.493, + -0.643, 0.891, 0.194, 0.086, 0.983, + -1.048, 2.032, 1.174, -0.441, -0.204, + -1.126, 0.933, 1.987, 0.638, 0.789, + 0.767, 0.676, -1.028, 1.422, 0.453, + ] + ) + data = data.reshape(2,2,10) data[0, 0] = [np.nan] * 10 da = xr.DataArray( data, @@ -86,11 +99,4 @@ 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 - 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 + assert np.isnan(out.values[0, 0]).all() From d6fce9b90aa2903e9997ea21f54b248ad5775fb0 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 11 Dec 2024 18:59:47 +0000 Subject: [PATCH 2/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/test_sdba/test_loess.py | 52 +++++++++++++++++++++++++++-------- 1 file changed, 41 insertions(+), 11 deletions(-) diff --git a/tests/test_sdba/test_loess.py b/tests/test_sdba/test_loess.py index 99281b740..cb50f388b 100644 --- a/tests/test_sdba/test_loess.py +++ b/tests/test_sdba/test_loess.py @@ -1,7 +1,5 @@ from __future__ import annotations -import logging - import numpy as np import pandas as pd import pytest @@ -77,17 +75,49 @@ def test_loess_smoothing_nan(use_dask): # (random array taken from np.random.randn) data = np.array( [ - -0.993, -0.980, -0.452, -0.076, 0.447, - 0.389, 2.408, 0.966, -0.793, 0.090, - -0.173, 1.713, -1.579, 0.454, -0.272, - -0.005, -0.926, -2.022, -1.661, -0.493, - -0.643, 0.891, 0.194, 0.086, 0.983, - -1.048, 2.032, 1.174, -0.441, -0.204, - -1.126, 0.933, 1.987, 0.638, 0.789, - 0.767, 0.676, -1.028, 1.422, 0.453, + -0.993, + -0.980, + -0.452, + -0.076, + 0.447, + 0.389, + 2.408, + 0.966, + -0.793, + 0.090, + -0.173, + 1.713, + -1.579, + 0.454, + -0.272, + -0.005, + -0.926, + -2.022, + -1.661, + -0.493, + -0.643, + 0.891, + 0.194, + 0.086, + 0.983, + -1.048, + 2.032, + 1.174, + -0.441, + -0.204, + -1.126, + 0.933, + 1.987, + 0.638, + 0.789, + 0.767, + 0.676, + -1.028, + 1.422, + 0.453, ] ) - data = data.reshape(2,2,10) + data = data.reshape(2, 2, 10) data[0, 0] = [np.nan] * 10 da = xr.DataArray( data, From 82e7cdfa1efd1bec7f832db62478e590df603a27 Mon Sep 17 00:00:00 2001 From: SarahG-579462 Date: Wed, 11 Dec 2024 20:02:45 +0000 Subject: [PATCH 3/4] format --- tests/test_sdba/test_loess.py | 54 +++++++++-------------------------- 1 file changed, 13 insertions(+), 41 deletions(-) diff --git a/tests/test_sdba/test_loess.py b/tests/test_sdba/test_loess.py index cb50f388b..4da732fd7 100644 --- a/tests/test_sdba/test_loess.py +++ b/tests/test_sdba/test_loess.py @@ -1,5 +1,7 @@ from __future__ import annotations +import logging + import numpy as np import pandas as pd import pytest @@ -73,50 +75,20 @@ def test_loess_smoothing(use_dask, open_dataset): def test_loess_smoothing_nan(use_dask): # create data with one axis full of nan # (random array taken from np.random.randn) + # fmt: off data = np.array( [ - -0.993, - -0.980, - -0.452, - -0.076, - 0.447, - 0.389, - 2.408, - 0.966, - -0.793, - 0.090, - -0.173, - 1.713, - -1.579, - 0.454, - -0.272, - -0.005, - -0.926, - -2.022, - -1.661, - -0.493, - -0.643, - 0.891, - 0.194, - 0.086, - 0.983, - -1.048, - 2.032, - 1.174, - -0.441, - -0.204, - -1.126, - 0.933, - 1.987, - 0.638, - 0.789, - 0.767, - 0.676, - -1.028, - 1.422, - 0.453, + -0.993, -0.980, -0.452, -0.076, 0.447, + 0.389, 2.408, 0.966, -0.793, 0.090, + -0.173, 1.713, -1.579, 0.454, -0.272, + -0.005, -0.926, -2.022, -1.661, -0.493, + -0.643, 0.891, 0.194, 0.086, 0.983, + -1.048, 2.032, 1.174, -0.441, -0.204, + -1.126, 0.933, 1.987, 0.638, 0.789, + 0.767, 0.676, -1.028, 1.422, 0.453, ] - ) + ) + # fmt: on data = data.reshape(2, 2, 10) data[0, 0] = [np.nan] * 10 da = xr.DataArray( From 19aae7994c96158669e2ed8cbdcb0638c9335bc6 Mon Sep 17 00:00:00 2001 From: Zeitsperre <10819524+Zeitsperre@users.noreply.github.com> Date: Wed, 11 Dec 2024 15:28:52 -0500 Subject: [PATCH 4/4] formatting exceptions --- tests/test_sdba/test_loess.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/test_sdba/test_loess.py b/tests/test_sdba/test_loess.py index 4da732fd7..c2d8ff5ec 100644 --- a/tests/test_sdba/test_loess.py +++ b/tests/test_sdba/test_loess.py @@ -1,7 +1,6 @@ +# ruff: noqa: E241 from __future__ import annotations -import logging - import numpy as np import pandas as pd import pytest @@ -13,7 +12,7 @@ _linear_regression, # noqa _loess_nb, # noqa _tricube_weighting, # noqa - loess_smoothing, + loess_smoothing, # noqa ) @@ -87,9 +86,9 @@ def test_loess_smoothing_nan(use_dask): -1.126, 0.933, 1.987, 0.638, 0.789, 0.767, 0.676, -1.028, 1.422, 0.453, ] - ) + ) # fmt: on - data = data.reshape(2, 2, 10) + data = data.reshape(2, 2, 10) # pylint: disable=too-many-function-args data[0, 0] = [np.nan] * 10 da = xr.DataArray( data,