Skip to content

Commit

Permalink
Fixed missing=0 in convert cal
Browse files Browse the repository at this point in the history
  • Loading branch information
aulemahal committed Dec 15, 2023
1 parent 85a2f74 commit d50331d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion tests/test_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
4 changes: 3 additions & 1 deletion xclim/core/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d50331d

Please sign in to comment.