From 57ddadda24badfd473700eee1f1cf64d4165ef4d Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Sun, 5 Dec 2021 17:29:42 -0800 Subject: [PATCH] TST: Add regression test for groupby rolling --- pandas/tests/window/test_groupby.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/pandas/tests/window/test_groupby.py b/pandas/tests/window/test_groupby.py index c4efcd140baae..05f485fcc3c65 100644 --- a/pandas/tests/window/test_groupby.py +++ b/pandas/tests/window/test_groupby.py @@ -838,6 +838,33 @@ def test_as_index_false(self, by, expected_data): ) tm.assert_frame_equal(result, expected) + def test_nan_and_zero_endpoints(self): + # https://github.com/twosigma/pandas/issues/53 + size = 1000 + idx = np.repeat(0, size) + idx[-1] = 1 + + val = 5e25 + arr = np.repeat(val, size) + arr[0] = np.nan + arr[-1] = 0 + + df = DataFrame( + { + "index": idx, + "adl2": arr, + } + ).set_index("index") + result = df.groupby("index")["adl2"].rolling(window=10, min_periods=1).mean() + expected = Series( + arr, + name="adl2", + index=MultiIndex.from_arrays( + [[0] * 999 + [1], [0] * 999 + [1]], names=["index", "index"] + ), + ) + tm.assert_series_equal(result, expected) + class TestExpanding: def setup_method(self):