Skip to content

TST: suppress rolling warnings correctly for raw= #27330

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 11, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions pandas/tests/window/test_window.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from collections import OrderedDict
import copy
from datetime import datetime, timedelta
import warnings
from warnings import catch_warnings
Expand Down Expand Up @@ -1536,21 +1537,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])
Expand Down Expand Up @@ -1676,6 +1676,12 @@ 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)(**kwargs)
Expand Down