(time_unit: PDDatetimeUnitOptions)
| 142 | |
| 143 | @requires_cftime |
| 144 | def 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 | |
| 170 | def test_decode_cf_datetime_non_standard_units() -> None: |
nothing calls this directly
no test coverage detected
searching dependent graphs…