Skip to content

Commit 35694f8

Browse files
authored
Fix sdba Grouper.get_coordinate after xarray update (#2038)
<!--Please ensure the PR fulfills the following requirements! --> <!-- If this is your first PR, make sure to add your details to the AUTHORS.rst! --> ### Pull Request Checklist: - [x] This PR addresses an already opened issue (for bug fixes / features) - This PR fixes #2037 - [ ] Tests for the changes have been added (for bug fixes / features) - [ ] (If applicable) Documentation has been added / updated (for bug fixes / features) - [ ] CHANGELOG.rst has been updated (with summary of main changes) - [ ] Link to issue (:issue:`number`) and pull request (:pull:`number`) has been added ### What kind of change does this PR introduce? * Uses a dumber way of getting the max doy, that doesn't rely on a private xarray function. There is a public xarray function in >=2024.09, but we still support >=2023.11. ### Does this PR introduce a breaking change? Yes, only if a non-uniform calendar was used with a subset of years that did not include a leap year. The max doy is now static (`standard => 366`, for example) and not dynamic (`standard, 2004 => 366`).
2 parents 4435256 + 378b0a8 commit 35694f8

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/xclim/sdba/base.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import xarray as xr
1616
from boltons.funcutils import wraps
1717

18-
from xclim.core.calendar import get_calendar
18+
from xclim.core.calendar import get_calendar, max_doy
1919
from xclim.core.options import OPTIONS, SDBA_ENCODE_CF
2020
from xclim.core.utils import uses_dask
2121

@@ -195,10 +195,8 @@ def get_coordinate(self, ds: xr.Dataset | None = None) -> xr.DataArray:
195195
if self.prop == "dayofyear":
196196
if ds is not None:
197197
cal = get_calendar(ds, dim=self.dim)
198-
mdoy = max(
199-
xr.coding.calendar_ops._days_in_year(yr, cal)
200-
for yr in np.unique(ds[self.dim].dt.year)
201-
)
198+
# TODO : Change this to `ds[self.dim].dt.days_in_year.max().item()` when minimum xarray is 2024.09
199+
mdoy = max_doy[cal]
202200
else:
203201
mdoy = 365
204202
return xr.DataArray(

0 commit comments

Comments
 (0)