-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Open
Labels
Description
What happened?
I want to use the xarray.cftime_range function to get a set of datetimes between two cftime.datetime objects that use the proleptic_gregorian calendar. However, when I use this function with this calendar, I receive the following error:
File "/Users/Alexander/miniconda3/envs/xrtest/lib/python3.11/site-packages/xarray/core/resample_cftime.py", line 491, in exact_cftime_datetime_difference
seconds = b.replace(microsecond=0) - a.replace(microsecond=0)
~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
File "src/cftime/_cftime.pyx", line 1574, in cftime._cftime.datetime.__sub__
TypeError: cannot compute the time difference between dates with different calendars
What did you expect to happen?
I expect this function to return a list of dates between the two dates I selected, with each date spaced by one day. In the minimal example, I provide the expected output obtained when I instead use the cftime.DatetimeProlepticGregorian object.
Minimal Complete Verifiable Example
#xarray==2024.3.0
#cftime==1.6.3
import xarray as xr
import cftime
start_date = cftime.DatetimeProlepticGregorian(1,1,1)
end_date = cftime.DatetimeProlepticGregorian(2,1,1)
daterange = xr.cftime_range(start_date, end_date, calendar='proleptic_gregorian')
print(daterange)
start_date = cftime.datetime(1,1,1,calendar = 'proleptic_gregorian')
end_date = cftime.datetime(2,1,1,calendar = 'proleptic_gregorian')
daterange = xr.cftime_range(start_date, end_date, calendar='proleptic_gregorian')
print(daterange)MVCE confirmation
- Minimal example — the example is as focused as reasonably possible to demonstrate the underlying issue in xarray.
- Complete example — the example is self-contained, including all data and the text of any traceback.
- Verifiable example — the example copy & pastes into an IPython prompt or Binder notebook, returning the result.
- New issue — a search of GitHub Issues suggests this is not a duplicate.
- Recent environment — the issue occurs with the latest version of xarray and its dependencies.
Relevant log output
No response
Anything else we need to know?
No response