From e1aabf9b8124832c23de3900875953ef86415c79 Mon Sep 17 00:00:00 2001 From: juliettelavoie Date: Thu, 4 Apr 2024 13:54:20 -0400 Subject: [PATCH 1/4] handle all nan case --- xclim/sdba/loess.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/xclim/sdba/loess.py b/xclim/sdba/loess.py index d98c4ff68..2a527d993 100644 --- a/xclim/sdba/loess.py +++ b/xclim/sdba/loess.py @@ -95,6 +95,8 @@ def _loess_nb( out = np.full(x.size, np.NaN) y = y[~nan] x = x[~nan] + if x.size == 0: + return out n = x.size yest = np.zeros(n) From f7acea38c1d529505c834f83318fb2074075085e Mon Sep 17 00:00:00 2001 From: juliettelavoie Date: Thu, 4 Apr 2024 14:16:17 -0400 Subject: [PATCH 2/4] add test --- CHANGES.rst | 3 ++- tests/test_sdba/test_loess.py | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index fd17a8049..8fe365690 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,7 +4,7 @@ Changelog v0.49.0 (unreleased) -------------------- -Contributors to this version: Trevor James Smith (:user:`Zeitsperre`), Pascal Bourgault (:user:`aulemahal`). +Contributors to this version: Trevor James Smith (:user:`Zeitsperre`), Pascal Bourgault (:user:`aulemahal`), Juliette Lavoie (:user:`juliettelavoie`). Announcements ^^^^^^^^^^^^^ @@ -14,6 +14,7 @@ Bug fixes ^^^^^^^^^ * Fixed an bug in sdba's ``map_groups`` that prevented passing DataArrays with cftime coordinates if the ``sdba_encode_cf`` option was True. (:issue:`1673`, :pull:`1674`). * Fixed bug (:issue:`1678`, :pull:`1679`) in sdba where a loaded training dataset could not be used for adjustment +* Fixed bug with loess smoothing for an array full of NaNs. (:pull:`1699`). Internal changes ^^^^^^^^^^^^^^^^ diff --git a/tests/test_sdba/test_loess.py b/tests/test_sdba/test_loess.py index 189bf6cb0..15835014e 100644 --- a/tests/test_sdba/test_loess.py +++ b/tests/test_sdba/test_loess.py @@ -1,7 +1,9 @@ from __future__ import annotations import numpy as np +import pandas as pd import pytest +import xarray as xr from xclim.sdba.loess import _constant_regression # noqa from xclim.sdba.loess import _gaussian_weighting # noqa @@ -62,3 +64,22 @@ def test_loess_smoothing(use_dask, open_dataset): # Same but we force not to use the optimization tasmooth3 = loess_smoothing(tas, f=0.1, equal_spacing=False) np.testing.assert_allclose(tasmooth, tasmooth3, rtol=1e-3, atol=1e-3) + + +@pytest.mark.slow +@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) + data[0, 0] = [np.nan] * 10 + da = xr.DataArray( + data, + dims=["scenario", "model", "time"], + coords={"time": pd.date_range("2000-01-01", periods=10, freq="YS")}, + ).chunk({"time": -1}) + + out = loess_smoothing(da) + + 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() From cea510b296c099f7eb1afae9a34665c77b111adc Mon Sep 17 00:00:00 2001 From: "bumpversion[bot]" Date: Fri, 5 Apr 2024 15:19:50 +0000 Subject: [PATCH 3/4] =?UTF-8?q?Bump=20version:=200.48.3-dev.4=20=E2=86=92?= =?UTF-8?q?=200.48.3-dev.5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 2 +- xclim/__init__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 7849847a2..d5a61354d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -123,7 +123,7 @@ target-version = [ ] [tool.bumpversion] -current_version = "0.48.3-dev.4" +current_version = "0.48.3-dev.5" commit = true commit_args = "--no-verify" tag = false diff --git a/xclim/__init__.py b/xclim/__init__.py index fe2fe55b8..ccc4ad28f 100644 --- a/xclim/__init__.py +++ b/xclim/__init__.py @@ -16,7 +16,7 @@ __author__ = """Travis Logan""" __email__ = "logan.travis@ouranos.ca" -__version__ = "0.48.3-dev.4" +__version__ = "0.48.3-dev.5" _module_data = _files("xclim.data") From dbd37f39ee532ffec7901aa48a5ca41d55ecc0bf Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 12 Apr 2024 12:15:21 +0000 Subject: [PATCH 4/4] Bump actions/add-to-project from 1.0.0 to 1.0.1 Bumps [actions/add-to-project](https://github.com/actions/add-to-project) from 1.0.0 to 1.0.1. - [Release notes](https://github.com/actions/add-to-project/releases) - [Commits](https://github.com/actions/add-to-project/compare/2e5cc851ca7162e9eb510e6da6a5c64022e606a7...9bfe908f2eaa7ba10340b31e314148fcfe6a2458) --- updated-dependencies: - dependency-name: actions/add-to-project dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .github/workflows/add-to-project.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/add-to-project.yml b/.github/workflows/add-to-project.yml index bca555414..d11e98554 100644 --- a/.github/workflows/add-to-project.yml +++ b/.github/workflows/add-to-project.yml @@ -24,7 +24,7 @@ jobs: allowed-endpoints: > api.github.com:443 - - uses: actions/add-to-project@2e5cc851ca7162e9eb510e6da6a5c64022e606a7 # v1.0.0 + - uses: actions/add-to-project@9bfe908f2eaa7ba10340b31e314148fcfe6a2458 # v1.0.1 with: project-url: https://github.com/orgs/Ouranosinc/projects/6 github-token: ${{ secrets.ADD_TO_PROJECT_TOKEN }}