Skip to content

Commit

Permalink
Avoid deprecated use_cftime (#461)
Browse files Browse the repository at this point in the history
### What kind of change does this PR introduce?

* Avoid use of `use_cftime` to adapt to the deprecation in the latest
xarray.

### Does this PR introduce a breaking change?
No.
  • Loading branch information
Zeitsperre authored Feb 18, 2025
2 parents 376ca2a + b0a7505 commit 9347963
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ Contributors
------------

* Louise Arnal <arnal.louise@ouranos.ca> `@lou-a <https://github.com/lou-a>`_
* Pascal Bourgault <bourgault.pascal@ouranos.ca> `@aulemahal <https://github.com/aulemaha>`_
11 changes: 7 additions & 4 deletions src/ravenpy/utilities/forecasting.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,13 +297,16 @@ def _shift_esp_time(nc, year, dim="member"):
Modify time such that it starts on the given year, and add member dimension with original year as value.
"""
ds = xr.open_dataset(nc, use_cftime=True)
ds = xr.open_dataset(nc)

# Create new time coordinate
start = ds.time.data[0]
start = ds.indexes["time"][0]
freq = xr.infer_freq(ds.time)
ds["time"] = xr.cftime_range(
start.replace(year=year), periods=len(ds.time), freq=freq
ds["time"] = xr.date_range(
start.replace(year=year),
periods=len(ds.time),
freq=freq,
calendar=ds.time.dt.calendar,
)

# New coordinate dimension to store the original year
Expand Down

0 comments on commit 9347963

Please sign in to comment.