Skip to content
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