Skip to content

Commit e62b184

Browse files
mroeschkeMatt Roeschke
and
Matt Roeschke
authored
CLN: test_moments_rolling.py for mean/std/var/count/median/min/max (#36678)
* CLN: test_moments_rolling.py for mean * Add missing test * Parameterize over more functions * Remove usused param since apply was moved * Remove copy import Co-authored-by: Matt Roeschke <[email protected]>
1 parent dca6c7f commit e62b184

File tree

2 files changed

+304
-74
lines changed

2 files changed

+304
-74
lines changed

pandas/tests/window/moments/test_moments_rolling.py

+2-74
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import copy
2-
31
import numpy as np
42
from numpy.random import randn
53
import pytest
@@ -26,12 +24,6 @@ def _check_moment_func(
2624
frame=None,
2725
**kwargs,
2826
):
29-
30-
# inject raw
31-
if name == "apply":
32-
kwargs = copy.copy(kwargs)
33-
kwargs["raw"] = raw
34-
3527
def get_result(obj, window, min_periods=None, center=False):
3628
r = obj.rolling(window=window, min_periods=min_periods, center=center)
3729
return getattr(r, name)(**kwargs)
@@ -211,34 +203,6 @@ def test_centered_axis_validation():
211203
(DataFrame(np.ones((10, 10))).rolling(window=3, center=True, axis=2).mean())
212204

213205

214-
def test_rolling_sum(raw, series, frame):
215-
_check_moment_func(
216-
np.nansum,
217-
name="sum",
218-
zero_min_periods_equal=False,
219-
raw=raw,
220-
series=series,
221-
frame=frame,
222-
)
223-
224-
225-
def test_rolling_count(raw, series, frame):
226-
counter = lambda x: np.isfinite(x).astype(float).sum()
227-
_check_moment_func(
228-
counter,
229-
name="count",
230-
has_min_periods=False,
231-
fill_value=0,
232-
raw=raw,
233-
series=series,
234-
frame=frame,
235-
)
236-
237-
238-
def test_rolling_mean(raw, series, frame):
239-
_check_moment_func(np.mean, name="mean", raw=raw, series=series, frame=frame)
240-
241-
242206
@td.skip_if_no_scipy
243207
def test_cmov_mean():
244208
# GH 8238
@@ -733,13 +697,7 @@ def test_cmov_window_special_linear_range(win_types_special):
733697
tm.assert_series_equal(xp, rs)
734698

735699

736-
def test_rolling_median(raw, series, frame):
737-
_check_moment_func(np.median, name="median", raw=raw, series=series, frame=frame)
738-
739-
740-
def test_rolling_min(raw, series, frame):
741-
_check_moment_func(np.min, name="min", raw=raw, series=series, frame=frame)
742-
700+
def test_rolling_min_min_periods():
743701
a = pd.Series([1, 2, 3, 4, 5])
744702
result = a.rolling(window=100, min_periods=1).min()
745703
expected = pd.Series(np.ones(len(a)))
@@ -749,9 +707,7 @@ def test_rolling_min(raw, series, frame):
749707
pd.Series([1, 2, 3]).rolling(window=3, min_periods=5).min()
750708

751709

752-
def test_rolling_max(raw, series, frame):
753-
_check_moment_func(np.max, name="max", raw=raw, series=series, frame=frame)
754-
710+
def test_rolling_max_min_periods():
755711
a = pd.Series([1, 2, 3, 4, 5], dtype=np.float64)
756712
b = a.rolling(window=100, min_periods=1).max()
757713
tm.assert_almost_equal(a, b)
@@ -855,20 +811,6 @@ def test_rolling_quantile_param():
855811
ser.rolling(3).quantile("foo")
856812

857813

858-
def test_rolling_std(raw, series, frame):
859-
_check_moment_func(
860-
lambda x: np.std(x, ddof=1), name="std", raw=raw, series=series, frame=frame
861-
)
862-
_check_moment_func(
863-
lambda x: np.std(x, ddof=0),
864-
name="std",
865-
ddof=0,
866-
raw=raw,
867-
series=series,
868-
frame=frame,
869-
)
870-
871-
872814
def test_rolling_std_1obs():
873815
vals = pd.Series([1.0, 2.0, 3.0, 4.0, 5.0])
874816

@@ -905,20 +847,6 @@ def test_rolling_std_neg_sqrt():
905847
assert np.isfinite(b[2:]).all()
906848

907849

908-
def test_rolling_var(raw, series, frame):
909-
_check_moment_func(
910-
lambda x: np.var(x, ddof=1), name="var", raw=raw, series=series, frame=frame
911-
)
912-
_check_moment_func(
913-
lambda x: np.var(x, ddof=0),
914-
name="var",
915-
ddof=0,
916-
raw=raw,
917-
series=series,
918-
frame=frame,
919-
)
920-
921-
922850
@td.skip_if_no_scipy
923851
def test_rolling_skew(raw, series, frame):
924852
from scipy.stats import skew

0 commit comments

Comments
 (0)