Skip to content

Commit

Permalink
Merge branch 'main' into pre-commit-ci-update-config
Browse files Browse the repository at this point in the history
  • Loading branch information
aulemahal authored Apr 12, 2024
2 parents 5804601 + a4ad253 commit c78ce1c
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/add-to-project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
^^^^^^^^^^^^^
Expand All @@ -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`).
* Fixed and adapted ``time_bnds`` to the newest xarray. (:pull:`1700`)

Internal changes
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions tests/test_sdba/test_loess.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()
2 changes: 1 addition & 1 deletion xclim/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

__author__ = """Travis Logan"""
__email__ = "[email protected]"
__version__ = "0.48.3-dev.4"
__version__ = "0.48.3-dev.5"


_module_data = _files("xclim.data")
Expand Down
2 changes: 2 additions & 0 deletions xclim/sdba/loess.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c78ce1c

Please sign in to comment.