(source, target, freq)
| 176 | ], |
| 177 | ) |
| 178 | def test_convert_calendar_missing(source, target, freq): |
| 179 | src = DataArray( |
| 180 | date_range( |
| 181 | "2004-01-01", |
| 182 | "2004-12-31" if source != "360_day" else "2004-12-30", |
| 183 | freq=freq, |
| 184 | calendar=source, |
| 185 | ), |
| 186 | dims=("time",), |
| 187 | name="time", |
| 188 | ) |
| 189 | da_src = DataArray( |
| 190 | np.linspace(0, 1, src.size), dims=("time",), coords={"time": src} |
| 191 | ) |
| 192 | out = convert_calendar(da_src, target, missing=np.nan, align_on="date") |
| 193 | |
| 194 | expected_freq = freq |
| 195 | assert infer_freq(out.time) == expected_freq |
| 196 | |
| 197 | expected = date_range( |
| 198 | "2004-01-01", |
| 199 | "2004-12-31" if target != "360_day" else "2004-12-30", |
| 200 | freq=freq, |
| 201 | calendar=target, |
| 202 | ) |
| 203 | np.testing.assert_array_equal(out.time, expected) |
| 204 | |
| 205 | if freq != "ME": |
| 206 | out_without_missing = convert_calendar(da_src, target, align_on="date") |
| 207 | expected_nan = out.isel(time=~out.time.isin(out_without_missing.time)) |
| 208 | assert expected_nan.isnull().all() |
| 209 | |
| 210 | expected_not_nan = out.sel(time=out_without_missing.time) |
| 211 | assert_identical(expected_not_nan, out_without_missing) |
| 212 | |
| 213 | |
| 214 | @requires_cftime |
nothing calls this directly
no test coverage detected
searching dependent graphs…