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

Method test_rolling_pandas_compat

xarray/tests/test_rolling.py:688–709  ·  view source on GitHub ↗
(self, center, window, min_periods)

Source from the content-addressed store, hash-verified

686 @pytest.mark.parametrize("min_periods", (None, 1, 2, 3))
687 @pytest.mark.parametrize("window", (1, 2, 3, 4))
688 def test_rolling_pandas_compat(self, center, window, min_periods) -> None:
689 df = pd.DataFrame(
690 {
691 "x": np.random.randn(20),
692 "y": np.random.randn(20),
693 "time": np.linspace(0, 1, 20),
694 }
695 )
696 ds = Dataset.from_dataframe(df)
697
698 if min_periods is not None and window < min_periods:
699 min_periods = window
700
701 df_rolling = df.rolling(window, center=center, min_periods=min_periods).mean()
702 ds_rolling = ds.rolling(
703 index=window, center=center, min_periods=min_periods
704 ).mean()
705
706 np.testing.assert_allclose(
707 np.asarray(df_rolling["x"].values), ds_rolling["x"].values
708 )
709 np.testing.assert_allclose(df_rolling.index, ds_rolling["index"])
710
711 @pytest.mark.parametrize("center", (True, False))
712 @pytest.mark.parametrize("window", (1, 2, 3, 4))

Callers

nothing calls this directly

Calls 4

linspaceMethod · 0.80
from_dataframeMethod · 0.80
meanMethod · 0.45
rollingMethod · 0.45

Tested by

no test coverage detected