Skip to content

Commit

Permalink
Add a check to ensure that doy bounds have same freq in mask_between_…
Browse files Browse the repository at this point in the history
…doys
  • Loading branch information
Baptiste Hamon committed Jan 28, 2025
1 parent 2e40c9f commit 0c815b9
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/xclim/core/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -1195,7 +1195,21 @@ def mask_between_doys(
end.attrs["calendar"] = cal
end = doy_to_days_since(end)

freq = xr.infer_freq(start.time)
freq = []
for bound in [start, end]:
try:
freq.append(xr.infer_freq(bound.time))
except ValueError:
freq.append(None)
freq = set(freq) - {None}
if len(freq) != 1:
raise ValueError(
f"Non-inferrable resampling frequency or inconsistent frequencies. Got start, end = {freq}."
" Please consider providing `freq` manually."
)
else:
freq = freq.pop()

out = []
for base_time, indexes in da.resample(time=freq).groups.items():
# get group slice
Expand Down

0 comments on commit 0c815b9

Please sign in to comment.