Skip to content

Commit 718bc9f

Browse files
authored
TST Add test for rolling window, see GH 34605 (#34705)
1 parent 0f17970 commit 718bc9f

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

pandas/tests/window/test_rolling.py

+33
Original file line numberDiff line numberDiff line change
@@ -663,3 +663,36 @@ def test_iter_rolling_datetime(expected, expected_index, window):
663663

664664
for (expected, actual) in zip(expected, ser.rolling(window)):
665665
tm.assert_series_equal(actual, expected)
666+
667+
668+
@pytest.mark.parametrize(
669+
"grouping,_index",
670+
[
671+
(
672+
{"level": 0},
673+
pd.MultiIndex.from_tuples(
674+
[(0, 0), (0, 0), (1, 1), (1, 1), (1, 1)], names=[None, None]
675+
),
676+
),
677+
(
678+
{"by": "X"},
679+
pd.MultiIndex.from_tuples(
680+
[(0, 0), (1, 0), (2, 1), (3, 1), (4, 1)], names=["X", None]
681+
),
682+
),
683+
],
684+
)
685+
def test_rolling_positional_argument(grouping, _index, raw):
686+
# GH 34605
687+
688+
def scaled_sum(*args):
689+
if len(args) < 2:
690+
raise ValueError("The function needs two arguments")
691+
array, scale = args
692+
return array.sum() / scale
693+
694+
df = DataFrame(data={"X": range(5)}, index=[0, 0, 1, 1, 1])
695+
696+
expected = DataFrame(data={"X": [0.0, 0.5, 1.0, 1.5, 2.0]}, index=_index)
697+
result = df.groupby(**grouping).rolling(1).apply(scaled_sum, raw=raw, args=(2,))
698+
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)