Skip to content

Commit cd56708

Browse files
pwsiegeljreback
authored andcommitted
BUG: RollingGroupBy.quantile ignores interpolation keyword argument (#29567)
1 parent e1cadfa commit cd56708

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

doc/source/whatsnew/v1.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,7 @@ Groupby/resample/rolling
437437
- Bug in :meth:`DataFrame.groupby` not offering selection by column name when ``axis=1`` (:issue:`27614`)
438438
- Bug in :meth:`DataFrameGroupby.agg` not able to use lambda function with named aggregation (:issue:`27519`)
439439
- Bug in :meth:`DataFrame.groupby` losing column name information when grouping by a categorical column (:issue:`28787`)
440+
- Bug in :meth:`DataFrameGroupBy.rolling().quantile()` ignoring ``interpolation`` keyword argument (:issue:`28779`)
440441

441442
Reshaping
442443
^^^^^^^^^

pandas/core/window/rolling.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1499,7 +1499,9 @@ def f(arg, *args, **kwargs):
14991499
interpolation,
15001500
)
15011501

1502-
return self._apply(f, "quantile", quantile=quantile, **kwargs)
1502+
return self._apply(
1503+
f, "quantile", quantile=quantile, interpolation=interpolation, **kwargs
1504+
)
15031505

15041506
_shared_docs[
15051507
"cov"

pandas/tests/window/test_grouper.py

+20-5
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ def test_rolling(self):
6060
r = g.rolling(window=4)
6161

6262
for f in ["sum", "mean", "min", "max", "count", "kurt", "skew"]:
63-
6463
result = getattr(r, f)()
6564
expected = g.apply(lambda x: getattr(x.rolling(4), f)())
6665
tm.assert_frame_equal(result, expected)
@@ -70,8 +69,16 @@ def test_rolling(self):
7069
expected = g.apply(lambda x: getattr(x.rolling(4), f)(ddof=1))
7170
tm.assert_frame_equal(result, expected)
7271

73-
result = r.quantile(0.5)
74-
expected = g.apply(lambda x: x.rolling(4).quantile(0.5))
72+
@pytest.mark.parametrize(
73+
"interpolation", ["linear", "lower", "higher", "midpoint", "nearest"]
74+
)
75+
def test_rolling_quantile(self, interpolation):
76+
g = self.frame.groupby("A")
77+
r = g.rolling(window=4)
78+
result = r.quantile(0.4, interpolation=interpolation)
79+
expected = g.apply(
80+
lambda x: x.rolling(4).quantile(0.4, interpolation=interpolation)
81+
)
7582
tm.assert_frame_equal(result, expected)
7683

7784
def test_rolling_corr_cov(self):
@@ -142,8 +149,16 @@ def test_expanding(self):
142149
expected = g.apply(lambda x: getattr(x.expanding(), f)(ddof=0))
143150
tm.assert_frame_equal(result, expected)
144151

145-
result = r.quantile(0.5)
146-
expected = g.apply(lambda x: x.expanding().quantile(0.5))
152+
@pytest.mark.parametrize(
153+
"interpolation", ["linear", "lower", "higher", "midpoint", "nearest"]
154+
)
155+
def test_expanding_quantile(self, interpolation):
156+
g = self.frame.groupby("A")
157+
r = g.expanding()
158+
result = r.quantile(0.4, interpolation=interpolation)
159+
expected = g.apply(
160+
lambda x: x.expanding().quantile(0.4, interpolation=interpolation)
161+
)
147162
tm.assert_frame_equal(result, expected)
148163

149164
def test_expanding_corr_cov(self):

0 commit comments

Comments
 (0)