MCPcopy Index your code
hub / github.com/pydata/xarray / to_cftime_datetime

Function to_cftime_datetime

xarray/coding/cftime_offsets.py:824–847  ·  view source on GitHub ↗
(date_str_or_date, calendar=None)

Source from the content-addressed store, hash-verified

822
823
824def to_cftime_datetime(date_str_or_date, calendar=None):
825 if TYPE_CHECKING:
826 import cftime
827 else:
828 cftime = attempt_import("cftime")
829
830 if isinstance(date_str_or_date, str):
831 if calendar is None:
832 raise ValueError(
833 "If converting a string to a cftime.datetime object, "
834 "a calendar type must be provided"
835 )
836 date, _ = _parse_iso8601(get_date_type(calendar), date_str_or_date)
837 return date
838 elif isinstance(date_str_or_date, cftime.datetime):
839 return date_str_or_date
840 elif isinstance(date_str_or_date, datetime | pd.Timestamp):
841 return cftime.DatetimeProlepticGregorian(*date_str_or_date.timetuple())
842 else:
843 raise TypeError(
844 "date_str_or_date must be a string or a "
845 "subclass of cftime.datetime. Instead got "
846 f"{date_str_or_date!r}."
847 )
848
849
850def normalize_date(date):

Calls 3

attempt_importFunction · 0.90
_parse_iso8601Function · 0.90
get_date_typeFunction · 0.70

Used in the wild real call sites across dependent graphs

searching dependent graphs…