From d50331d63c57bb1ce5f476f53187a3e9048f1a57 Mon Sep 17 00:00:00 2001 From: Pascal Bourgault Date: Fri, 15 Dec 2023 13:47:09 -0500 Subject: [PATCH] Fixed missing=0 in convert cal --- CHANGES.rst | 3 +++ tests/test_calendar.py | 3 ++- xclim/core/calendar.py | 4 +++- 3 files changed, 8 insertions(+), 2 deletions(-) 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)