diff --git a/CHANGES.rst b/CHANGES.rst index 67ec1c0ff..10ef59099 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,7 +4,7 @@ Changelog v0.47.0 (unreleased) -------------------- -Contributors to this version: Juliette Lavoie (:user:`juliettelavoie`), Pascal Bourgault (:user:`aulemahal`), Trevor James Smith (:user:`Zeitsperre`), David Huard (:user:`huard`). +Contributors to this version: Juliette Lavoie (:user:`juliettelavoie`), Pascal Bourgault (:user:`aulemahal`), Trevor James Smith (:user:`Zeitsperre`), David Huard (:user:`huard`), Éric Dupuis (:user:`coxipi`). Announcements ^^^^^^^^^^^^^ @@ -20,7 +20,7 @@ Bug fixes ^^^^^^^^^ * Fixed a bug with ``n_escore=-1`` in ``xclim.sdba.adjustment.NpdfTransform``. (:issue:`1515`, :pull:`1515`). * In the documentation, fix the tooltips in the indicator search results. (:issue:`1524`, :pull:`1527`). -* If chunked inputs are passed to indicators ``mean_radiant_temperature`` and ``potential_evapotranspiration``, sub-calculations of the solar angle will also use the same chunks, instead of a single one of the same size as the data. (:issue:`1536`, :pull:`1542`). +* If chunked inputs are passed to indicators ``mean_radiant_temperature`` and ``potential_evapotranspiration``, sub-calculations of the solar angle will also use the same chunks, instead of a single one of the same size as the data. (:issue:`1536`, :pull:`1542`). Internal changes ^^^^^^^^^^^^^^^^ @@ -28,6 +28,7 @@ Internal changes * `pip check` in conda builds in GitHub workflows have been temporarily set to always pass. (:pull:`1531`). * Configure RtD search rankings to emphasize notebooks and indicators over indices and raw source code. (:pull:`1526`). * Addressed around 100 very basic `mypy` typing errors and call signature errors. (:pull:`1532`). +* Use the intermediate step ``_cumsum_reset_on_zero`` instead of ``rle`` which is sufficient in ``_boundary_run``. (:issue:`1405`, :pull:`1530`). v0.46.0 (2023-10-24) -------------------- diff --git a/xclim/indices/run_length.py b/xclim/indices/run_length.py index 3ca9607a0..855f4e4c3 100644 --- a/xclim/indices/run_length.py +++ b/xclim/indices/run_length.py @@ -416,7 +416,7 @@ def _boundary_run( ufunc_1dim: str | bool, position: str, ) -> xr.DataArray: - """Return the index of the first item of the first run of at least a given length. + """Return the index of the first item of the first or last run of at least a given length. Parameters ---------- @@ -493,9 +493,10 @@ def find_boundary_run(runs, position): out = coord_transform(out, da) else: - # for "first" run, return "first" element in the run (and conversely for "last" run) - d = rle(da, dim=dim, index=position) + # _cusum_reset_on_zero() is an intermediate step in rle, which is sufficient here + d = _cumsum_reset_on_zero(da, dim=dim, index=position) d = xr.where(d >= window, 1, 0) + # for "first" run, return "first" element in the run (and conversely for "last" run) if freq is not None: out = d.resample({dim: freq}).map(find_boundary_run, position=position) else: