Skip to content

Commit 2d0b20b

Browse files
authored
TST: suppress rolling warnings correctly for raw= (#27330)
1 parent 472af55 commit 2d0b20b

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

pandas/tests/window/test_window.py

+18-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from collections import OrderedDict
2+
import copy
23
from datetime import datetime, timedelta
34
import warnings
45
from warnings import catch_warnings
@@ -1536,21 +1537,20 @@ def test_rolling_apply(self, raw):
15361537
# suppress warnings about empty slices, as we are deliberately testing
15371538
# with a 0-length Series
15381539

1539-
with warnings.catch_warnings():
1540-
warnings.filterwarnings(
1541-
"ignore",
1542-
message=".*(empty slice|0 for slice).*",
1543-
category=RuntimeWarning,
1544-
)
1545-
1546-
def f(x):
1540+
def f(x):
1541+
with warnings.catch_warnings():
1542+
warnings.filterwarnings(
1543+
"ignore",
1544+
message=".*(empty slice|0 for slice).*",
1545+
category=RuntimeWarning,
1546+
)
15471547
return x[np.isfinite(x)].mean()
15481548

1549-
self._check_moment_func(np.mean, name="apply", func=f, raw=raw)
1549+
self._check_moment_func(np.mean, name="apply", func=f, raw=raw)
15501550

1551-
expected = Series([])
1552-
result = expected.rolling(10).apply(lambda x: x.mean(), raw=raw)
1553-
tm.assert_series_equal(result, expected)
1551+
expected = Series([])
1552+
result = expected.rolling(10).apply(lambda x: x.mean(), raw=raw)
1553+
tm.assert_series_equal(result, expected)
15541554

15551555
# gh-8080
15561556
s = Series([None, None, None])
@@ -1676,6 +1676,12 @@ def _check_moment_func(
16761676
zero_min_periods_equal=True,
16771677
**kwargs
16781678
):
1679+
1680+
# inject raw
1681+
if name == "apply":
1682+
kwargs = copy.copy(kwargs)
1683+
kwargs["raw"] = raw
1684+
16791685
def get_result(obj, window, min_periods=None, center=False):
16801686
r = obj.rolling(window=window, min_periods=min_periods, center=center)
16811687
return getattr(r, name)(**kwargs)

0 commit comments

Comments
 (0)