Skip to content

Commit 6312a8f

Browse files
authored
CLN/TST: Remove redundant/unnecessary windows/moments tests (#44239)
1 parent 135adfb commit 6312a8f

File tree

5 files changed

+77
-266
lines changed

5 files changed

+77
-266
lines changed

ci/run_tests.sh

+1-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ fi
2222
PYTEST_CMD="${XVFB}pytest -m \"$PATTERN\" -n $PYTEST_WORKERS --dist=loadfile $TEST_ARGS $COVERAGE $PYTEST_TARGET"
2323

2424
if [[ $(uname) != "Linux" && $(uname) != "Darwin" ]]; then
25-
# GH#37455 windows py38 build appears to be running out of memory
26-
# skip collection of window tests
27-
PYTEST_CMD="$PYTEST_CMD --ignore=pandas/tests/window/moments --ignore=pandas/tests/plotting/"
25+
PYTEST_CMD="$PYTEST_CMD --ignore=pandas/tests/plotting/"
2826
fi
2927

3028
echo $PYTEST_CMD
+37-127
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import itertools
2+
13
import numpy as np
24
import pytest
35

@@ -12,133 +14,20 @@
1214
def _create_consistency_data():
1315
def create_series():
1416
return [
15-
Series(dtype=object),
16-
Series([np.nan]),
17-
Series([np.nan, np.nan]),
18-
Series([3.0]),
19-
Series([np.nan, 3.0]),
20-
Series([3.0, np.nan]),
21-
Series([1.0, 3.0]),
22-
Series([2.0, 2.0]),
23-
Series([3.0, 1.0]),
24-
Series(
25-
[5.0, 5.0, 5.0, 5.0, np.nan, np.nan, np.nan, 5.0, 5.0, np.nan, np.nan]
26-
),
27-
Series(
28-
[
29-
np.nan,
30-
5.0,
31-
5.0,
32-
5.0,
33-
np.nan,
34-
np.nan,
35-
np.nan,
36-
5.0,
37-
5.0,
38-
np.nan,
39-
np.nan,
40-
]
41-
),
42-
Series(
43-
[
44-
np.nan,
45-
np.nan,
46-
5.0,
47-
5.0,
48-
np.nan,
49-
np.nan,
50-
np.nan,
51-
5.0,
52-
5.0,
53-
np.nan,
54-
np.nan,
55-
]
56-
),
57-
Series(
58-
[
59-
np.nan,
60-
3.0,
61-
np.nan,
62-
3.0,
63-
4.0,
64-
5.0,
65-
6.0,
66-
np.nan,
67-
np.nan,
68-
7.0,
69-
12.0,
70-
13.0,
71-
14.0,
72-
15.0,
73-
]
74-
),
75-
Series(
76-
[
77-
np.nan,
78-
5.0,
79-
np.nan,
80-
2.0,
81-
4.0,
82-
0.0,
83-
9.0,
84-
np.nan,
85-
np.nan,
86-
3.0,
87-
12.0,
88-
13.0,
89-
14.0,
90-
15.0,
91-
]
92-
),
93-
Series(
94-
[
95-
2.0,
96-
3.0,
97-
np.nan,
98-
3.0,
99-
4.0,
100-
5.0,
101-
6.0,
102-
np.nan,
103-
np.nan,
104-
7.0,
105-
12.0,
106-
13.0,
107-
14.0,
108-
15.0,
109-
]
110-
),
111-
Series(
112-
[
113-
2.0,
114-
5.0,
115-
np.nan,
116-
2.0,
117-
4.0,
118-
0.0,
119-
9.0,
120-
np.nan,
121-
np.nan,
122-
3.0,
123-
12.0,
124-
13.0,
125-
14.0,
126-
15.0,
127-
]
128-
),
129-
Series(range(10)),
130-
Series(range(20, 0, -2)),
17+
Series(dtype=np.float64, name="a"),
18+
Series([np.nan] * 5),
19+
Series([1.0] * 5),
20+
Series(range(5, 0, -1)),
21+
Series(range(5)),
22+
Series([np.nan, 1.0, np.nan, 1.0, 1.0]),
23+
Series([np.nan, 1.0, np.nan, 2.0, 3.0]),
24+
Series([np.nan, 1.0, np.nan, 3.0, 2.0]),
13125
]
13226

13327
def create_dataframes():
13428
return [
135-
DataFrame(),
136-
DataFrame(columns=["a"]),
13729
DataFrame(columns=["a", "a"]),
138-
DataFrame(columns=["a", "b"]),
139-
DataFrame(np.arange(10).reshape((5, 2))),
140-
DataFrame(np.arange(25).reshape((5, 5))),
141-
DataFrame(np.arange(25).reshape((5, 5)), columns=["a", "b", 99, "d", "d"]),
30+
DataFrame(np.arange(15).reshape((5, 3)), columns=["a", "a", 99]),
14231
] + [DataFrame(s) for s in create_series()]
14332

14433
def is_constant(x):
@@ -148,13 +37,34 @@ def is_constant(x):
14837
def no_nans(x):
14938
return x.notna().all().all()
15039

151-
# data is a tuple(object, is_constant, no_nans)
152-
data = create_series() + create_dataframes()
153-
154-
return [(x, is_constant(x), no_nans(x)) for x in data]
40+
return [
41+
(x, is_constant(x), no_nans(x))
42+
for x in itertools.chain(create_dataframes(), create_dataframes())
43+
]
15544

15645

15746
@pytest.fixture(params=_create_consistency_data())
15847
def consistency_data(request):
159-
"""Create consistency data"""
48+
"""
49+
Test:
50+
- Empty Series / DataFrame
51+
- All NaN
52+
- All consistent value
53+
- Monotonically decreasing
54+
- Monotonically increasing
55+
- Monotonically consistent with NaNs
56+
- Monotonically increasing with NaNs
57+
- Monotonically decreasing with NaNs
58+
"""
59+
return request.param
60+
61+
62+
@pytest.fixture(params=[(1, 0), (5, 1)])
63+
def rolling_consistency_cases(request):
64+
"""window, min_periods"""
65+
return request.param
66+
67+
68+
@pytest.fixture(params=[0, 2])
69+
def min_periods(request):
16070
return request.param

pandas/tests/window/moments/test_moments_consistency_ewm.py

+3-20
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def create_mock_weights(obj, com, adjust, ignore_na):
1818
create_mock_series_weights(
1919
obj.iloc[:, i], com=com, adjust=adjust, ignore_na=ignore_na
2020
)
21-
for i, _ in enumerate(obj.columns)
21+
for i in range(len(obj.columns))
2222
],
2323
axis=1,
2424
)
@@ -58,7 +58,6 @@ def create_mock_series_weights(s, com, adjust, ignore_na):
5858
return w
5959

6060

61-
@pytest.mark.parametrize("min_periods", [0, 1, 2, 3, 4])
6261
def test_ewm_consistency_mean(consistency_data, adjust, ignore_na, min_periods):
6362
x, is_constant, no_nans = consistency_data
6463
com = 3.0
@@ -76,7 +75,6 @@ def test_ewm_consistency_mean(consistency_data, adjust, ignore_na, min_periods):
7675
tm.assert_equal(result, expected.astype("float64"))
7776

7877

79-
@pytest.mark.parametrize("min_periods", [0, 1, 2, 3, 4])
8078
def test_ewm_consistency_consistent(consistency_data, adjust, ignore_na, min_periods):
8179
x, is_constant, no_nans = consistency_data
8280
com = 3.0
@@ -102,7 +100,6 @@ def test_ewm_consistency_consistent(consistency_data, adjust, ignore_na, min_per
102100
tm.assert_equal(corr_x_x, expected)
103101

104102

105-
@pytest.mark.parametrize("min_periods", [0, 1, 2, 3, 4])
106103
def test_ewm_consistency_var_debiasing_factors(
107104
consistency_data, adjust, ignore_na, min_periods
108105
):
@@ -128,7 +125,6 @@ def test_ewm_consistency_var_debiasing_factors(
128125
tm.assert_equal(var_unbiased_x, var_biased_x * var_debiasing_factors_x)
129126

130127

131-
@pytest.mark.parametrize("min_periods", [0, 1, 2, 3, 4])
132128
@pytest.mark.parametrize("bias", [True, False])
133129
def test_moments_consistency_var(
134130
consistency_data, adjust, ignore_na, min_periods, bias
@@ -154,7 +150,6 @@ def test_moments_consistency_var(
154150
tm.assert_equal(var_x, mean_x2 - (mean_x * mean_x))
155151

156152

157-
@pytest.mark.parametrize("min_periods", [0, 1, 2, 3, 4])
158153
@pytest.mark.parametrize("bias", [True, False])
159154
def test_moments_consistency_var_constant(
160155
consistency_data, adjust, ignore_na, min_periods, bias
@@ -176,34 +171,23 @@ def test_moments_consistency_var_constant(
176171
tm.assert_equal(var_x, expected)
177172

178173

179-
@pytest.mark.parametrize("min_periods", [0, 1, 2, 3, 4])
180174
@pytest.mark.parametrize("bias", [True, False])
181175
def test_ewm_consistency_std(consistency_data, adjust, ignore_na, min_periods, bias):
182176
x, is_constant, no_nans = consistency_data
183177
com = 3.0
184178
var_x = x.ewm(
185179
com=com, min_periods=min_periods, adjust=adjust, ignore_na=ignore_na
186180
).var(bias=bias)
181+
assert not (var_x < 0).any().any()
182+
187183
std_x = x.ewm(
188184
com=com, min_periods=min_periods, adjust=adjust, ignore_na=ignore_na
189185
).std(bias=bias)
190-
assert not (var_x < 0).any().any()
191186
assert not (std_x < 0).any().any()
192187

193188
# check that var(x) == std(x)^2
194189
tm.assert_equal(var_x, std_x * std_x)
195190

196-
197-
@pytest.mark.parametrize("min_periods", [0, 1, 2, 3, 4])
198-
@pytest.mark.parametrize("bias", [True, False])
199-
def test_ewm_consistency_cov(consistency_data, adjust, ignore_na, min_periods, bias):
200-
x, is_constant, no_nans = consistency_data
201-
com = 3.0
202-
var_x = x.ewm(
203-
com=com, min_periods=min_periods, adjust=adjust, ignore_na=ignore_na
204-
).var(bias=bias)
205-
assert not (var_x < 0).any().any()
206-
207191
cov_x_x = x.ewm(
208192
com=com, min_periods=min_periods, adjust=adjust, ignore_na=ignore_na
209193
).cov(x, bias=bias)
@@ -213,7 +197,6 @@ def test_ewm_consistency_cov(consistency_data, adjust, ignore_na, min_periods, b
213197
tm.assert_equal(var_x, cov_x_x)
214198

215199

216-
@pytest.mark.parametrize("min_periods", [0, 1, 2, 3, 4])
217200
@pytest.mark.parametrize("bias", [True, False])
218201
def test_ewm_consistency_series_cov_corr(
219202
consistency_data, adjust, ignore_na, min_periods, bias

0 commit comments

Comments
 (0)