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

Function test_calendars

xarray/tests/test_cftimeindex_resample.py:225–244  ·  view source on GitHub ↗
(calendar: str)

Source from the content-addressed store, hash-verified

223 "calendar", ["gregorian", "noleap", "all_leap", "360_day", "julian"]
224)
225def test_calendars(calendar: str) -> None:
226 # Limited testing for non-standard calendars
227 freq, closed, label = "8001min", None, None
228 xr_index = xr.date_range(
229 start="2004-01-01T12:07:01",
230 periods=7,
231 freq="3D",
232 calendar=calendar,
233 use_cftime=True,
234 )
235 pd_index = pd.date_range(
236 start="2004-01-01T12:07:01", periods=7, freq="3D", unit="ns"
237 )
238 da_cftime = da(xr_index).resample(time=freq, closed=closed, label=label).mean()
239 da_datetime = da(pd_index).resample(time=freq, closed=closed, label=label).mean()
240 # TODO (benbovy - flexible indexes): update when CFTimeIndex is an xarray Index subclass
241 new_pd_index = da_cftime.xindexes["time"].to_pandas_index()
242 assert isinstance(new_pd_index, CFTimeIndex) # shouldn't that be a pd.Index?
243 da_cftime["time"] = new_pd_index.to_datetimeindex(time_unit="ns")
244 xr.testing.assert_identical(da_cftime, da_datetime)
245
246
247class DateRangeKwargs(TypedDict):

Callers

nothing calls this directly

Calls 5

to_datetimeindexMethod · 0.80
daFunction · 0.70
meanMethod · 0.45
resampleMethod · 0.45
to_pandas_indexMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…