diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 7959ee2c3..650639fc2 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -2,13 +2,14 @@ Changelog ========= -v0.54 (unpublished) +v0.54.0 (unreleased) -------------------- -Contributors to this version: Éric (:user:`coxipi`). +Contributors to this version: Éric Dupuis (:user:`coxipi`), Pascal Bourgault (:user:`aulemahal`). Bug fixes ^^^^^^^^^ * Conversion of units of multivariate DataArray is now properly handled in `sdba.TrainAdjust` and `sdba.Adjust`. There was a bug where the units could be changed before a conversion of the magntitudes could occur. (:pull:`1972`). +* Fix for indicators that output "delta" Celsius degrees. (:pull:`1973`). v0.53.1 (2024-10-21) -------------------- diff --git a/tests/test_indicators.py b/tests/test_indicators.py index 997d2719b..d61b77bd7 100644 --- a/tests/test_indicators.py +++ b/tests/test_indicators.py @@ -286,6 +286,20 @@ def test_temp_unit_conversion(tas_series): np.testing.assert_array_almost_equal(txk, txc + 273.15) +def test_temp_diff_unit_conversion(tasmax_series, tasmin_series): + tx = tasmax_series(np.arange(365) + 1, start="2001-01-01") + tn = tasmin_series(np.arange(365), start="2001-01-01") + txC = convert_units_to(tx, "degC") + tnC = convert_units_to(tn, "degC") + + ind = xclim.atmos.daily_temperature_range.from_dict( + {"units": "degC"}, "dtr_degC", "test" + ) + out = ind(tasmax=txC, tasmin=tnC) + assert out.attrs["units"] == "degC" + assert out.attrs["units_metadata"] == "temperature: difference" + + def test_multiindicator(tas_series): tas = tas_series(np.arange(366), start="2000-01-01") tmin, tmax = multiTemp(tas, freq="YS") diff --git a/xclim/core/indicator.py b/xclim/core/indicator.py index 3023eb906..768a580c8 100644 --- a/xclim/core/indicator.py +++ b/xclim/core/indicator.py @@ -853,7 +853,7 @@ def __call__(self, *args, **kwds): # Convert to output units outs = [ - convert_units_to(out, attrs["units"], self.context) + convert_units_to(out, attrs, self.context) for out, attrs in zip(outs, out_attrs, strict=False) ]