MCPcopy
hub / github.com/pydata/xarray / _should_cftime_be_used

Function _should_cftime_be_used

xarray/coding/times.py:919–943  ·  view source on GitHub ↗

Return whether conversion of the source to the target calendar should result in a cftime-backed array. Source is a 1D datetime array, target_cal a string (calendar name) and use_cftime is a boolean or None. If use_cftime is None, this returns True if the source's range and target ca

(
    source, target_calendar: str, use_cftime: bool | None
)

Source from the content-addressed store, hash-verified

917
918
919def _should_cftime_be_used(
920 source, target_calendar: str, use_cftime: bool | None
921) -> bool:
922 """Return whether conversion of the source to the target calendar should
923 result in a cftime-backed array.
924
925 Source is a 1D datetime array, target_cal a string (calendar name) and
926 use_cftime is a boolean or None. If use_cftime is None, this returns True
927 if the source's range and target calendar are convertible to np.datetime64 objects.
928 """
929 # Arguments Checks for target
930 if use_cftime is not True:
931 if _is_standard_calendar(target_calendar):
932 if _is_numpy_compatible_time_range(source):
933 # Conversion is possible with pandas, force False if it was None
934 return False
935 elif use_cftime is False:
936 raise ValueError(
937 "Source time range is not valid for numpy datetimes. Try using `use_cftime=True`."
938 )
939 elif use_cftime is False:
940 raise ValueError(
941 f"Calendar '{target_calendar}' is only valid with cftime. Try using `use_cftime=True`."
942 )
943 return True
944
945
946def _cleanup_netcdf_time_units(units: str) -> str:

Calls 2

_is_standard_calendarFunction · 0.85

Used in the wild real call sites across dependent graphs

searching dependent graphs…