|
1 | 1 | from collections import OrderedDict
|
| 2 | +import copy |
2 | 3 | from datetime import datetime, timedelta
|
3 | 4 | import warnings
|
4 | 5 | from warnings import catch_warnings
|
@@ -1536,21 +1537,20 @@ def test_rolling_apply(self, raw):
|
1536 | 1537 | # suppress warnings about empty slices, as we are deliberately testing
|
1537 | 1538 | # with a 0-length Series
|
1538 | 1539 |
|
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 | + ) |
1547 | 1547 | return x[np.isfinite(x)].mean()
|
1548 | 1548 |
|
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) |
1550 | 1550 |
|
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) |
1554 | 1554 |
|
1555 | 1555 | # gh-8080
|
1556 | 1556 | s = Series([None, None, None])
|
@@ -1676,6 +1676,12 @@ def _check_moment_func(
|
1676 | 1676 | zero_min_periods_equal=True,
|
1677 | 1677 | **kwargs
|
1678 | 1678 | ):
|
| 1679 | + |
| 1680 | + # inject raw |
| 1681 | + if name == "apply": |
| 1682 | + kwargs = copy.copy(kwargs) |
| 1683 | + kwargs["raw"] = raw |
| 1684 | + |
1679 | 1685 | def get_result(obj, window, min_periods=None, center=False):
|
1680 | 1686 | r = obj.rolling(window=window, min_periods=min_periods, center=center)
|
1681 | 1687 | return getattr(r, name)(**kwargs)
|
|
0 commit comments