From ca1c2d7905d7de883188c2a475debe4e740ae556 Mon Sep 17 00:00:00 2001 From: Pascal Bourgault Date: Thu, 5 Oct 2023 10:39:26 -0400 Subject: [PATCH 1/4] Snow season length is 0 if there is 0 snow --- CHANGES.rst | 3 ++- tests/test_indices.py | 11 ++++++----- tests/test_snow.py | 9 ++++++--- xclim/indices/_threshold.py | 4 ++-- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index c2cbeb354..a42a51f8f 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,7 +4,7 @@ Changelog v0.46.0 (unreleased) -------------------- -Contributors to this version: Éric Dupuis (:user:`coxipi`), Trevor James Smith (:user:`Zeitsperre`), David Huard (:user:`huard`). +Contributors to this version: Éric Dupuis (:user:`coxipi`), Trevor James Smith (:user:`Zeitsperre`), David Huard (:user:`huard`) and Pascal Bourgault (:user:`aulemahal`). New features and enhancements ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -19,6 +19,7 @@ Bug fixes * Fixed an error in the `pytest` configuration that prevented copying of testing data to thread-safe caches of workers under certain conditions (this should always occur). (:pull:`1473`). * Coincidentally, this also fixes an error that caused `pytest` to error-out when invoked without an active internet connection. Running `pytest` without network access is now supported (requires cached testing data). (:issue:`1468`). * Calling a ``sdba.map_blocks``-wrapped function with data chunked along the reduced dimensions will raise an error. This forbids chunking the trained dataset along the distribution dimensions, for example. (:issue:`1481`, :pull:`1482`). +* Indicators ``snd_season_length`` and ``snw_season_length`` will return 0 instead of NaN if all inputs have a (non-NaN) 0 snow depth (or water-equivalent thickness). (:pull:`1492`, :issue:`1491`) Breaking changes ^^^^^^^^^^^^^^^^ diff --git a/tests/test_indices.py b/tests/test_indices.py index 613669582..609906c3c 100644 --- a/tests/test_indices.py +++ b/tests/test_indices.py @@ -2682,20 +2682,21 @@ def test_nan_slices(self, snd_series, snw_series): class TestSnowCover: - def test_snow_season_length(self, snd_series, snw_series): - a = np.ones(366) / 100.0 - a[10:20] = 0.3 + @pytest.mark.parametrize("length", [0, 10]) + def test_snow_season_length(self, snd_series, snw_series, length): + a = np.zeros(366) + a[10 : 10 + length] = 0.3 snd = snd_series(a) # kg m-2 = 1000 kg m-3 * 1 m snw = snw_series(1000 * a) out = xci.snd_season_length(snd) assert len(out) == 2 - assert out[0] == 10 + assert out[0] == length out = xci.snw_season_length(snw) assert len(out) == 2 - assert out[0] == 10 + assert out[0] == length def test_continous_snow_season_start(self, snd_series, snw_series): a = np.arange(366) / 100.0 diff --git a/tests/test_snow.py b/tests/test_snow.py index 58fc75315..2ed405a77 100644 --- a/tests/test_snow.py +++ b/tests/test_snow.py @@ -25,11 +25,14 @@ def test_simple(self, snd_series): class TestSnowWaterCoverDuration: - def test_simple(self, snw_series): - snw = snw_series(np.ones(110) * 1000, start="2001-01-01") + @pytest.mark.parametrize( + "factor,exp", ([1000, [31, 28, 31, np.NaN]], [0, [0, 0, 0, np.NaN]]) + ) + def test_simple(self, snw_series, factor, exp): + snw = snw_series(np.ones(110) * factor, start="2001-01-01") out = land.snw_season_length(snw, freq="M") assert out.units == "days" - np.testing.assert_array_equal(out, [31, 28, 31, np.nan]) + np.testing.assert_array_equal(out, exp) class TestContinuousSnowDepthCoverStartEnd: diff --git a/xclim/indices/_threshold.py b/xclim/indices/_threshold.py index b6e14bb78..636da9cbb 100644 --- a/xclim/indices/_threshold.py +++ b/xclim/indices/_threshold.py @@ -2069,7 +2069,7 @@ def snd_season_length( xarray.DataArray, [time] Number of days where snow depth is greater than or equal to threshold. """ - valid = at_least_n_valid(snd.where(snd > 0), n=1, freq=freq) + valid = at_least_n_valid(snd, n=1, freq=freq) thresh = convert_units_to(thresh, snd) out = threshold_count(snd, op, thresh, freq) return to_agg_units(out, snd, "count").where(~valid) @@ -2106,7 +2106,7 @@ def snw_season_length( xarray.DataArray, [time] Number of days where snow water is greater than or equal to threshold. """ - valid = at_least_n_valid(snw.where(snw > 0), n=1, freq=freq) + valid = at_least_n_valid(snw, n=1, freq=freq) thresh = convert_units_to(thresh, snw) out = threshold_count(snw, op, thresh, freq) return to_agg_units(out, snw, "count").where(~valid) From d66e47f3d79b646b6fda538b902dbde05ec0c597 Mon Sep 17 00:00:00 2001 From: Pascal Bourgault Date: Thu, 5 Oct 2023 13:19:51 -0400 Subject: [PATCH 2/4] fix typo --- xclim/indices/helpers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xclim/indices/helpers.py b/xclim/indices/helpers.py index e830decec..54d825d05 100644 --- a/xclim/indices/helpers.py +++ b/xclim/indices/helpers.py @@ -296,7 +296,7 @@ def cosine_of_solar_zenith_angle( _wrap_radians(h_e), stat == "average", input_core_dims=[[]] * 6, - dask="parallel", + dask="parallelized", ) From afbf309885215cc18b813f734a9de879c6965f13 Mon Sep 17 00:00:00 2001 From: Pascal Bourgault Date: Wed, 11 Oct 2023 15:31:37 -0400 Subject: [PATCH 3/4] Update CHANGES.rst Co-authored-by: David Huard --- CHANGES.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index a42a51f8f..778804be4 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -19,7 +19,7 @@ Bug fixes * Fixed an error in the `pytest` configuration that prevented copying of testing data to thread-safe caches of workers under certain conditions (this should always occur). (:pull:`1473`). * Coincidentally, this also fixes an error that caused `pytest` to error-out when invoked without an active internet connection. Running `pytest` without network access is now supported (requires cached testing data). (:issue:`1468`). * Calling a ``sdba.map_blocks``-wrapped function with data chunked along the reduced dimensions will raise an error. This forbids chunking the trained dataset along the distribution dimensions, for example. (:issue:`1481`, :pull:`1482`). -* Indicators ``snd_season_length`` and ``snw_season_length`` will return 0 instead of NaN if all inputs have a (non-NaN) 0 snow depth (or water-equivalent thickness). (:pull:`1492`, :issue:`1491`) +* Indicators ``snd_season_length`` and ``snw_season_length`` will return 0 instead of NaN if all inputs have a (non-NaN) zero snow depth (or water-equivalent thickness). (:pull:`1492`, :issue:`1491`) Breaking changes ^^^^^^^^^^^^^^^^ From 24e670f78c39ef27a5ec51c23d1329a00b67bc61 Mon Sep 17 00:00:00 2001 From: Zeitsperre <10819524+Zeitsperre@users.noreply.github.com> Date: Fri, 13 Oct 2023 14:18:34 -0400 Subject: [PATCH 4/4] finish for coveralls when only running py39 --- .github/workflows/main.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8413d770a..8f25ab154 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -75,6 +75,8 @@ jobs: run: tox -e ${{ matrix.tox-env }} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + COVERALLS_FLAG_NAME: run-{{ matrix.tox-env }} + COVERALLS_SERVICE_NAME: github test-pypi: needs: lint