Skip to content

Commit

Permalink
Fix sdba Grouper.get_coordinate after xarray update (#2038)
Browse files Browse the repository at this point in the history
<!--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`).
  • Loading branch information
aulemahal authored Jan 16, 2025
2 parents 4435256 + 378b0a8 commit 35694f8
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/xclim/sdba/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import xarray as xr
from boltons.funcutils import wraps

from xclim.core.calendar import get_calendar
from xclim.core.calendar import get_calendar, max_doy
from xclim.core.options import OPTIONS, SDBA_ENCODE_CF
from xclim.core.utils import uses_dask

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

0 comments on commit 35694f8

Please sign in to comment.