Skip to content

More robust checks for cftime input to xr.date_range #10065

Open
@kafitzgerald

Description

@kafitzgerald

What is your issue?

I recently ran into a case where the logic in xr.date_range isn't quite robust enough (detail below).

This is something we use in a downstream package and while I can definitely add some additional checks there I figured I'd log an issue here and see if you all might be open to addressing this in Xarray. Happy to work on a PR if that's helpful (though I'm not terribly familiar with the code).

The following example should replicate the failure:

import xarray as xr

times = xr.cftime_range(start='2020-01-01', end='2021-12-31', freq='D')
xr.date_range(start=times[0], end=times[-1], freq='D', calendar=times.calendar)

Resulting in:

TypeError: Cannot convert input [2020-01-01 00:00:00] of type <class 'cftime._cftime.DatetimeGregorian'> to Timestamp

Because of the "standard" calendar and an error that doesn't match the one Xarray is looking for it uses the pd.date_range rather than the cftime equivalent and then fails.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions