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

Function test_decode_cf_datetime_overflow

xarray/tests/test_coding_times.py:144–167  ·  view source on GitHub ↗
(time_unit: PDDatetimeUnitOptions)

Source from the content-addressed store, hash-verified

142
143@requires_cftime
144def test_decode_cf_datetime_overflow(time_unit: PDDatetimeUnitOptions) -> None:
145 # checks for
146 # https://github.com/pydata/pandas/issues/14068
147 # https://github.com/pydata/xarray/issues/975
148 from cftime import DatetimeGregorian
149
150 datetime = DatetimeGregorian
151 units = "days since 2000-01-01 00:00:00"
152
153 # date after 2262 and before 1678
154 days = (-117710, 95795)
155 expected = (datetime(1677, 9, 20), datetime(2262, 4, 12))
156 for i, day in enumerate(days):
157 with warnings.catch_warnings():
158 warnings.filterwarnings("ignore", "Unable to decode time axis")
159 result = decode_cf_datetime(
160 day, units, calendar="standard", time_unit=time_unit
161 )
162 assert result == expected[i]
163 # additional check to see if type/dtypes are correct
164 if time_unit == "ns":
165 assert isinstance(result.item(), datetime)
166 else:
167 assert result.dtype == np.dtype(f"=M8[{time_unit}]")
168
169
170def test_decode_cf_datetime_non_standard_units() -> None:

Callers

nothing calls this directly

Calls 2

decode_cf_datetimeFunction · 0.90
dtypeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…