From 2169983aa1fe58a384e8f3a8c2cd832b4af730ef Mon Sep 17 00:00:00 2001 From: Jeff Reback Date: Wed, 10 Jul 2019 16:35:53 -0500 Subject: [PATCH 1/2] TST: suppress rolling warnings correctly for raw= --- pandas/tests/window/test_window.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/pandas/tests/window/test_window.py b/pandas/tests/window/test_window.py index d85e22de1d176..3700741f44bbf 100644 --- a/pandas/tests/window/test_window.py +++ b/pandas/tests/window/test_window.py @@ -1536,21 +1536,20 @@ def test_rolling_apply(self, raw): # suppress warnings about empty slices, as we are deliberately testing # with a 0-length Series - with warnings.catch_warnings(): - warnings.filterwarnings( - "ignore", - message=".*(empty slice|0 for slice).*", - category=RuntimeWarning, - ) - - def f(x): + def f(x): + with warnings.catch_warnings(): + warnings.filterwarnings( + "ignore", + message=".*(empty slice|0 for slice).*", + category=RuntimeWarning, + ) return x[np.isfinite(x)].mean() - self._check_moment_func(np.mean, name="apply", func=f, raw=raw) + self._check_moment_func(np.mean, name="apply", func=f, raw=raw) - expected = Series([]) - result = expected.rolling(10).apply(lambda x: x.mean(), raw=raw) - tm.assert_series_equal(result, expected) + expected = Series([]) + result = expected.rolling(10).apply(lambda x: x.mean(), raw=raw) + tm.assert_series_equal(result, expected) # gh-8080 s = Series([None, None, None]) @@ -1678,7 +1677,7 @@ def _check_moment_func( ): def get_result(obj, window, min_periods=None, center=False): r = obj.rolling(window=window, min_periods=min_periods, center=center) - return getattr(r, name)(**kwargs) + return getattr(r, name)(raw=raw, **kwargs) series_result = get_result(self.series, window=50) assert isinstance(series_result, Series) From 355d94b7c3a2cc08a6a9fa28dacff93adb36606d Mon Sep 17 00:00:00 2001 From: Jeff Reback Date: Wed, 10 Jul 2019 18:36:57 -0500 Subject: [PATCH 2/2] correctly inject raw --- pandas/tests/window/test_window.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pandas/tests/window/test_window.py b/pandas/tests/window/test_window.py index 3700741f44bbf..2f3b83e172795 100644 --- a/pandas/tests/window/test_window.py +++ b/pandas/tests/window/test_window.py @@ -1,4 +1,5 @@ from collections import OrderedDict +import copy from datetime import datetime, timedelta import warnings from warnings import catch_warnings @@ -1675,9 +1676,15 @@ def _check_moment_func( zero_min_periods_equal=True, **kwargs ): + + # inject raw + if name == "apply": + kwargs = copy.copy(kwargs) + kwargs["raw"] = raw + def get_result(obj, window, min_periods=None, center=False): r = obj.rolling(window=window, min_periods=min_periods, center=center) - return getattr(r, name)(raw=raw, **kwargs) + return getattr(r, name)(**kwargs) series_result = get_result(self.series, window=50) assert isinstance(series_result, Series)