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

Function test_convert_calendar_missing

xarray/tests/test_calendar_ops.py:178–211  ·  view source on GitHub ↗
(source, target, freq)

Source from the content-addressed store, hash-verified

176 ],
177)
178def 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

Callers

nothing calls this directly

Calls 11

DataArrayClass · 0.90
date_rangeFunction · 0.90
convert_calendarFunction · 0.90
infer_freqFunction · 0.90
assert_identicalFunction · 0.90
linspaceMethod · 0.80
isinMethod · 0.80
iselMethod · 0.45
allMethod · 0.45
isnullMethod · 0.45
selMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…