MCPcopy Index your code
hub / github.com/pydata/xarray / test_rolling_count_correct

Method test_rolling_count_correct

xarray/tests/test_rolling.py:288–322  ·  view source on GitHub ↗
(self, compute_backend)

Source from the content-addressed store, hash-verified

286 assert actual.sizes == expected.sizes
287
288 def test_rolling_count_correct(self, compute_backend) -> None:
289 da = DataArray([0, np.nan, 1, 2, np.nan, 3, 4, 5, np.nan, 6, 7], dims="time")
290
291 kwargs: list[dict[str, Any]] = [
292 {"time": 11, "min_periods": 1},
293 {"time": 11, "min_periods": None},
294 {"time": 7, "min_periods": 2},
295 ]
296 expecteds = [
297 DataArray([1, 1, 2, 3, 3, 4, 5, 6, 6, 7, 8], dims="time"),
298 DataArray(
299 [
300 np.nan,
301 np.nan,
302 np.nan,
303 np.nan,
304 np.nan,
305 np.nan,
306 np.nan,
307 np.nan,
308 np.nan,
309 np.nan,
310 np.nan,
311 ],
312 dims="time",
313 ),
314 DataArray([np.nan, np.nan, 2, 3, 3, 4, 5, 5, 5, 5, 5], dims="time"),
315 ]
316
317 for kwarg, expected in zip(kwargs, expecteds, strict=True):
318 result = da.rolling(**kwarg).count()
319 assert_equal(result, expected)
320
321 result = da.to_dataset(name="var1").rolling(**kwarg).count()["var1"]
322 assert_equal(result, expected)
323
324 @pytest.mark.parametrize("da", (1,), indirect=True)
325 @pytest.mark.parametrize("center", (True, False))

Callers

nothing calls this directly

Calls 6

rollingMethod · 0.95
to_datasetMethod · 0.95
DataArrayClass · 0.90
assert_equalFunction · 0.90
countMethod · 0.45
rollingMethod · 0.45

Tested by

no test coverage detected