Skip to content

Commit

Permalink
Fix warnings issued from successive convert_units_to calls (#1319)
Browse files Browse the repository at this point in the history
### What kind of change does this PR introduce?

* Fixes a bug in the logic of two indices (`snowfall_approximation` with
`method="brown"`, `effective_growing_degree_days`) that was emitting
usage warnings from valid calls.
* prepends `v` to entries in CHANGES.rst to properly generate hyperlink
entries.
* Warnings from set ``_version_deprecated`` within Indicators now emit
`FutureWarning` instead of `DeprecationWarning` for greater visibility.

### Does this PR introduce a breaking change?

No.

### Other information:

See also: #1010
  • Loading branch information
Zeitsperre authored Mar 23, 2023
2 parents 9c12b90 + 22dbb2c commit 00bd949
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 18 deletions.
29 changes: 17 additions & 12 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
Changelog
=========

0.42.0 (unreleased)
-------------------
v0.42.0 (unreleased)
--------------------
Contributors to this version: Trevor James Smith (:user:`Zeitsperre`).

New features and enhancements
Expand All @@ -13,6 +13,10 @@ New features and enhancements
* ``xclim.core.calendar.yearly_random_doy``
* `scipy` is no longer pinned below v1.9 and `lmoments3>=1.0.5` is now a core dependency and installed by default with `pip`. (:issue:`1142`, :pull:`1171`).

Bug fixes
^^^^^^^^^
* Warnings emitted from regular usage of some indices (``snowfall_approximation`` with ``method="brown"``, ``effective_growing_degree_days``) due to successive ``convert_units_to`` calls within their logic have been silenced. (:pull:`1319`).

Breaking changes
^^^^^^^^^^^^^^^^
* The call signatures for ``xclim.ensembles.create_ensemble`` and ``xclim.ensembles._base._ens_align_dataset`` have been deprecated. Calls to these functions made with the original signature will emit warnings. Changes will become breaking in `xclim>=0.43.0`.(:issue:`1305`, :pull:`1317`). Affected variable:
Expand All @@ -39,9 +43,10 @@ Internal changes
* Addressed a formatting bug that caused `Indicators` with multiple variables returned to not be properly formatted in the documentation. (:issue:`1305`, :pull:`1317`).
* `tox` now include `sbck` and `eofs` flags for easier testing of dependencies. CI builds now test against `sbck-python` @ master. (:pull:`1328`).
* `upstream` CI tests are now run on push to master, at midnight, and can also be triggered via `workflow_dispatch`. Failures from upstream build will open issues using `xarray-contrib/issue-from-pytest-log`. (:pull:`1327`).
* Warnings from set ``_version_deprecated`` within Indicators now emit ``FutureWarning`` instead of ``DeprecationWarning`` for greater visibility. (:pull:`1319`).

0.41.0 (2023-02-28)
-------------------
v0.41.0 (2023-02-28)
--------------------
Contributors to this version: Trevor James Smith (:user:`Zeitsperre`), Pascal Bourgault (:user:`aulemahal`), Ludwig Lierhammer (:user:`ludwiglierhammer`), Éric Dupuis (:user:`coxipi`).

New features and enhancements
Expand Down Expand Up @@ -94,8 +99,8 @@ Internal changes
* Added `sphinxcontrib-svg2pdfconverter` for converting SVG graphics within documentation to PDF-compatible images. (:pull:`1296`).
* README badges for supported Python versions and repository health have been added. (:issue:`1304`, :pull:`1307`).

0.40.0 (2023-01-13)
-------------------
v0.40.0 (2023-01-13)
--------------------
Contributors to this version: Trevor James Smith (:user:`Zeitsperre`), Pascal Bourgault (:user:`aulemahal`), David Huard (:user:`huard`), Juliette Lavoie (:user:`juliettelavoie`).

New features and enhancements
Expand Down Expand Up @@ -150,8 +155,8 @@ Internal changes
* A notebook (``extendingxclim.ipynb``) has been updated to remove mentions of obsolete `xclim.subset` module. (:pull:`1258`).
* Merge of sdba documentation from the module and the rst files, some cleanup and addition of a section referring to GitHub issues. (:pull:`1230`).

0.39.0 (2022-11-02)
-------------------
v0.39.0 (2022-11-02)
--------------------
Contributors to this version: Trevor James Smith (:user:`Zeitsperre`), Abel Aoun (:user:`bzah`), Éric Dupuis (:user:`coxipi`), Travis Logan (:user:`tlogan2000`), Pascal Bourgault (:user:`aulemahal`).

New features and enhancements
Expand Down Expand Up @@ -213,8 +218,8 @@ Internal changes
* ``show_versions`` can now accept a list of dependencies so that other libraries can make use of this utility. (:pull:`1215`).
* Pull Requests now are automatically tagged (``CI``, ``docs``, ``indicators``, and/or ``sdba``) according to files modified using the `GitHub Labeler Action <https://github.com/actions/labeler>`_. (:pull:`1214`).

0.38.0 (2022-09-06)
-------------------
v0.38.0 (2022-09-06)
--------------------
Contributors to this version: Pascal Bourgault (:user:`aulemahal`), Éric Dupuis (:user:`coxipi`), Trevor James Smith (:user:`Zeitsperre`), Abel Aoun (:user:`bzah`), Gabriel Rondeau-Genesse (:user:`RondeauG`), Dougie Squire (:user:`dougiesquire`).

New features and enhancements
Expand Down Expand Up @@ -287,8 +292,8 @@ Internal changes
* Adjusted the ANUCLIM indices by removing "ANUCLIM" from their titles, modifying their docstrings, and handling `"op"` input in a more user-friendly way. (:issue:`1055`, :pull:`1169`).
* Documentation for fire-based indices/indicators has been reorganized to reflect the new submodule structure. (:pull:`1159`).

0.37.0 (2022-06-20)
-------------------
v0.37.0 (2022-06-20)
--------------------
Contributors to this version: Abel Aoun (:user:`bzah`), Pascal Bourgault (:user:`aulemahal`), Trevor James Smith (:user:`Zeitsperre`), Gabriel Rondeau-Genesse (:user:`RondeauG`), Juliette Lavoie (:user:`juliettelavoie`), Ludwig Lierhammer (:user:`ludwiglierhammer`).

Announcements
Expand Down
7 changes: 4 additions & 3 deletions xclim/core/indicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1350,9 +1350,10 @@ def injected_parameters(self):

def _show_deprecation_warning(self):
warnings.warn(
f"`{self.title}` is deprecated as of xclim v{self._version_deprecated}. "
f"See the xclim release notes for more information.",
DeprecationWarning,
f"`{self.title}` is deprecated as of `xclim` v{self._version_deprecated} and will be removed "
"in a future release. See the `xclim` release notes for more information: "
f"https://xclim.readthedocs.io/en/stable/history.html",
FutureWarning,
stacklevel=3,
)

Expand Down
7 changes: 5 additions & 2 deletions xclim/indices/_agro.py
Original file line number Diff line number Diff line change
Expand Up @@ -1332,17 +1332,20 @@ def effective_growing_degree_days(
tasmax = convert_units_to(tasmax, "degC")
tasmin = convert_units_to(tasmin, "degC")
thresh = convert_units_to(thresh, "degC")
thresh_with_units = f"{thresh} degC"

tas = (tasmin + tasmax) / 2
tas.attrs["units"] = "degC"

if method.lower() == "bootsma":
fda = first_day_temperature_above(tas=tas, thresh=thresh, window=1, freq=freq)
fda = first_day_temperature_above(
tas=tas, thresh=thresh_with_units, window=1, freq=freq
)
start = fda + 10
elif method.lower() == "qian":
tas_weighted = qian_weighted_mean_average(tas=tas, dim=dim)
start = first_day_temperature_above(
tas_weighted, thresh=thresh, window=5, freq=freq
tas_weighted, thresh=thresh_with_units, window=5, freq=freq
)
else:
raise NotImplementedError(f"Method: {method}.")
Expand Down
3 changes: 2 additions & 1 deletion xclim/indices/_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,8 @@ def snowfall_approximation(
raise ValueError("Non-scalar `thresh` are not allowed with method `brown`.")

# Freezing point + 2C in the native units
upper = convert_units_to(convert_units_to(thresh, "degC") + 2, tas)
thresh_plus_2 = convert_units_to(thresh, "degC") + 2
upper = convert_units_to(f"{thresh_plus_2} degC", tas)
thresh = convert_units_to(thresh, tas)

# Interpolate fraction over temperature (in units of tas)
Expand Down

0 comments on commit 00bd949

Please sign in to comment.