diff --git a/CHANGES.rst b/CHANGES.rst index 0b2f4705c..46fd3b9f2 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -11,6 +11,9 @@ New features and enhancements * Added uncertainty partitioning method `lafferty_sriver` from Lafferty and Sriver (2023), which can partition uncertainty related to the downscaling method. (:issue:`1497`, :pull:`1529`). * Validate YAML indicators description before trying to build module. (:issue:`1523`, :pull:`1560`). +Bug fixes +^^^^^^^^^ +* Fixed passing ``missing=0`` to ``xclim.core.calendar.convert_calendar`` (:issue:`1562`, :pull:`1563`). v0.47.0 (2023-12-01) diff --git a/tests/test_calendar.py b/tests/test_calendar.py index 625e603e9..f9631cd5c 100644 --- a/tests/test_calendar.py +++ b/tests/test_calendar.py @@ -413,10 +413,11 @@ def test_convert_calendar_missing(source, target, freq): da_src = xr.DataArray( np.linspace(0, 1, src.size), dims=("time",), coords={"time": src} ) - out = convert_calendar(da_src, target, missing=np.nan, align_on="date") + out = convert_calendar(da_src, target, missing=0, align_on="date") assert xr.infer_freq(out.time) == freq if source == "360_day": assert out.time[-1].dt.day == 31 + assert out[-1] == 0 def test_convert_calendar_and_doy(): diff --git a/xclim/core/calendar.py b/xclim/core/calendar.py index dfbb3cb61..74c2b2b28 100644 --- a/xclim/core/calendar.py +++ b/xclim/core/calendar.py @@ -503,7 +503,9 @@ def convert_calendar( target = date_range_like(source[dim], cal_tgt) if isinstance(target, xr.DataArray): - out = out.reindex({dim: target}, fill_value=missing or np.nan) + out = out.reindex( + {dim: target}, fill_value=missing if missing is not None else np.nan + ) # Copy attrs but change remove `calendar` is still present. out[dim].attrs.update(source[dim].attrs)