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

Function _is_numpy_compatible_time_range

xarray/coding/times.py:108–132  ·  view source on GitHub ↗
(times)

Source from the content-addressed store, hash-verified

106
107
108def _is_numpy_compatible_time_range(times):
109 if is_np_datetime_like(times.dtype):
110 return True
111 # times array contains cftime objects
112 times = np.asarray(times)
113 tmin = times.min()
114 tmax = times.max()
115 try:
116 # before relaxing the nanosecond constrained
117 # this raised OutOfBoundsDatetime for
118 # times < 1678 and times > 2262
119 # this isn't the case anymore for other resolutions like "s"
120 # now, we raise for dates before 1582-10-15
121 _check_date_is_after_shift(tmin, "standard")
122 _check_date_is_after_shift(tmax, "standard")
123 convert_time_or_go_back(tmin, pd.Timestamp)
124 convert_time_or_go_back(tmax, pd.Timestamp)
125 except pd.errors.OutOfBoundsDatetime:
126 return False
127 except ValueError as err:
128 if err.args[0] == "year 0 is out of range":
129 return False
130 raise
131 else:
132 return True
133
134
135def _netcdf_to_numpy_timeunit(units: str) -> NPDatetimeUnitOptions:

Callers 1

_should_cftime_be_usedFunction · 0.85

Calls 5

is_np_datetime_likeFunction · 0.90
convert_time_or_go_backFunction · 0.85
minMethod · 0.45
maxMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…