Skip to content

Commit f574426

Browse files
committed
fix: use hardcoded values for tests
1 parent 2699bec commit f574426

File tree

1 file changed

+56
-98
lines changed

1 file changed

+56
-98
lines changed

pandas/tests/window/test_rolling.py

Lines changed: 56 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
)
55

66
import numpy as np
7-
from numpy.lib.stride_tricks import sliding_window_view
87
import pytest
98

109
from pandas.compat import (
@@ -1081,132 +1080,91 @@ def test_rolling_sem(frame_or_series):
10811080

10821081

10831082
@pytest.mark.parametrize(
1084-
("func", "values", "window", "ddof", "exp_value"),
1083+
("func", "values", "window", "ddof", "expected_values"),
10851084
[
1085+
("var", [99999999999999999, 1, 1, 2, 3, 1, 1], 2, 1, [5e33, 0, 0.5, 0.5, 2, 0]),
10861086
(
1087-
"var",
1088-
[
1089-
2.72993945,
1090-
1.58444294,
1091-
4.14371708,
1092-
4.92961687,
1093-
2.7138744,
1094-
3.48168586,
1095-
0.69505519,
1096-
1.87511994,
1097-
4.20167276,
1098-
0.04797675,
1099-
],
1100-
3,
1087+
"std",
1088+
[99999999999999999, 1, 1, 2, 3, 1, 1],
1089+
2,
11011090
1,
1102-
"numpy_compute",
1091+
[7.071068e16, 0, 0.7071068, 0.7071068, 1.414214, 0],
11031092
),
1093+
("var", [99999999999999999, 1, 2, 2, 3, 1, 1], 2, 1, [5e33, 0.5, 0, 0.5, 2, 0]),
11041094
(
11051095
"std",
1106-
[
1107-
2.72993945,
1108-
1.58444294,
1109-
4.14371708,
1110-
4.92961687,
1111-
2.7138744,
1112-
3.48168586,
1113-
0.69505519,
1114-
1.87511994,
1115-
4.20167276,
1116-
0.04797675,
1117-
],
1118-
3,
1096+
[99999999999999999, 1, 2, 2, 3, 1, 1],
1097+
2,
1098+
1,
1099+
[7.071068e16, 0.7071068, 0, 0.7071068, 1.414214, 0],
1100+
),
1101+
(
1102+
"std",
1103+
[1.2e03, 1.3e17, 1.5e17, 1.995e03, 1.990e03],
1104+
2,
11191105
1,
1120-
"numpy_compute",
1106+
[9.192388e16, 1.414214e16, 1.060660e17, 3.535534e00],
11211107
),
11221108
(
11231109
"var",
11241110
[
1125-
2.72993945,
1126-
1.58444294,
1127-
4.14371708,
1128-
4.92961687,
1129-
2.7138744,
1130-
3.48168586,
1131-
0.69505519,
1132-
1.87511994,
1133-
4.20167276,
1134-
0.04797675,
1111+
0.00000000e00,
1112+
0.00000000e00,
1113+
3.16188252e-18,
1114+
2.95781651e-16,
1115+
2.23153542e-51,
1116+
0.00000000e00,
1117+
0.00000000e00,
1118+
5.39943432e-48,
1119+
1.38206260e-73,
1120+
0.00000000e00,
11351121
],
1136-
2,
1122+
3,
11371123
1,
1138-
"numpy_compute",
1124+
[
1125+
3.33250036e-036,
1126+
2.88538519e-032,
1127+
2.88538519e-032,
1128+
2.91622617e-032,
1129+
1.65991678e-102,
1130+
9.71796366e-096,
1131+
9.71796366e-096,
1132+
9.71796366e-096,
1133+
],
11391134
),
11401135
(
11411136
"std",
1137+
[1, -1, 0, 1, 3, 2, -2, 10000000000, 1, 2, 0, -2, 1, 3, 0, 1],
1138+
6,
1139+
1,
11421140
[
1143-
2.72993945,
1144-
1.58444294,
1145-
4.14371708,
1146-
4.92961687,
1147-
2.7138744,
1148-
3.48168586,
1149-
0.69505519,
1150-
1.87511994,
1151-
4.20167276,
1152-
0.04797675,
1141+
1.41421356e00,
1142+
1.87082869e00,
1143+
4.08248290e09,
1144+
4.08248290e09,
1145+
4.08248290e09,
1146+
4.08248290e09,
1147+
4.08248290e09,
1148+
4.08248290e09,
1149+
1.72240142e00,
1150+
1.75119007e00,
1151+
1.64316767e00,
11531152
],
1154-
2,
1155-
1,
1156-
"numpy_compute",
11571153
),
1158-
("var", [99999999999999999, 1, 1, 2, 3, 1, 1], 2, 1, 0),
1159-
("std", [99999999999999999, 1, 1, 2, 3, 1, 1], 2, 1, 0),
1160-
("var", [99999999999999999, 1, 2, 2, 3, 1, 1], 2, 1, 0),
1161-
("std", [99999999999999999, 1, 2, 2, 3, 1, 1], 2, 1, 0),
1162-
("var", [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0], 5, 0, "numpy_compute"),
11631154
],
11641155
)
1165-
def test_rolling_var_correctness(func, values, window, ddof, exp_value):
1166-
# This tests subsume the previous tests under test_rolling_var_numerical_issues
1167-
# GH: 37051, 42064, 54333
1156+
def test_rolling_var_correctness(func, values, window, ddof, expected_values):
1157+
# GH: 37051, 42064, 54518, 52407, 47721
11681158
ts = Series(values)
11691159
result = getattr(ts.rolling(window=window, center=True), func)(ddof=ddof)
11701160
if result.last_valid_index():
11711161
result = result[
11721162
result.first_valid_index() : result.last_valid_index() + 1
11731163
].reset_index(drop=True)
1174-
expected = Series(
1175-
getattr(sliding_window_view(values, window_shape=window), func)(
1176-
axis=-1, ddof=ddof
1177-
)
1178-
)
1164+
expected = Series(expected_values)
11791165
tm.assert_series_equal(result, expected, atol=1e-55)
11801166
# GH 42064
1181-
if exp_value == 0:
1182-
# new `roll_var` will output 0.0 correctly
1183-
tm.assert_series_equal(result == 0, expected == 0)
1184-
1185-
1186-
def test_rolling_var_numerical_stability():
1187-
# GH 52407
1188-
A = [
1189-
0.00000000e00,
1190-
0.00000000e00,
1191-
3.16188252e-18,
1192-
2.95781651e-16,
1193-
2.23153542e-51,
1194-
0.00000000e00,
1195-
0.00000000e00,
1196-
5.39943432e-48,
1197-
1.38206260e-73,
1198-
0.00000000e00,
1199-
]
1200-
ts = Series(A)
1201-
1202-
result = ts.rolling(window=3, center=True).var(ddof=1)
1203-
result = result[
1204-
result.first_valid_index() : result.last_valid_index() + 1
1205-
].reset_index(drop=True)
1206-
1207-
# numpy implementation
1208-
expected = Series(sliding_window_view(A, window_shape=3).var(axis=-1, ddof=1))
1209-
tm.assert_series_equal(result, expected, atol=1e-55)
1167+
tm.assert_series_equal(result == 0, expected == 0)
12101168

12111169

12121170
def test_timeoffset_as_window_parameter_for_corr(unit):

0 commit comments

Comments
 (0)