(
num_dates,
units: str,
minimum_resolution: PDDatetimeUnitOptions,
calendar: str,
time_unit: PDDatetimeUnitOptions,
)
| 104 | ["num_dates", "units", "minimum_resolution", "calendar"], _CF_DATETIME_TESTS |
| 105 | ) |
| 106 | def test_cf_datetime( |
| 107 | num_dates, |
| 108 | units: str, |
| 109 | minimum_resolution: PDDatetimeUnitOptions, |
| 110 | calendar: str, |
| 111 | time_unit: PDDatetimeUnitOptions, |
| 112 | ) -> None: |
| 113 | import cftime |
| 114 | |
| 115 | expected = cftime.num2date( |
| 116 | num_dates, units, calendar, only_use_cftime_datetimes=True |
| 117 | ) |
| 118 | |
| 119 | with warnings.catch_warnings(): |
| 120 | warnings.filterwarnings("ignore", "Unable to decode time axis") |
| 121 | actual = decode_cf_datetime(num_dates, units, calendar, time_unit=time_unit) |
| 122 | |
| 123 | if actual.dtype.kind != "O": |
| 124 | if np.timedelta64(1, time_unit) > np.timedelta64(1, minimum_resolution): |
| 125 | expected_unit = minimum_resolution |
| 126 | else: |
| 127 | expected_unit = time_unit |
| 128 | expected = cftime_to_nptime(expected, time_unit=expected_unit) |
| 129 | |
| 130 | assert_array_equal(actual, expected) |
| 131 | encoded1, _, _ = encode_cf_datetime(actual, units, calendar) |
| 132 | |
| 133 | assert_array_equal(num_dates, encoded1) |
| 134 | |
| 135 | if hasattr(num_dates, "ndim") and num_dates.ndim == 1 and "1000" not in units: |
| 136 | # verify that wrapping with a pandas.Index works |
| 137 | # note that it *does not* currently work to put |
| 138 | # non-datetime64 compatible dates into a pandas.Index |
| 139 | encoded2, _, _ = encode_cf_datetime(pd.Index(actual), units, calendar) |
| 140 | assert_array_equal(num_dates, encoded2) |
| 141 | |
| 142 | |
| 143 | @requires_cftime |
nothing calls this directly
no test coverage detected
searching dependent graphs…