Skip to content

Commit fea0d10

Browse files
committed
lint: reformatted by pre-commit run
1 parent ac2dd40 commit fea0d10

File tree

1 file changed

+109
-26
lines changed

1 file changed

+109
-26
lines changed

pandas/tests/window/test_rolling.py

Lines changed: 109 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,10 @@
55

66
import numpy as np
77
from numpy.lib.stride_tricks import sliding_window_view
8-
9-
108
import pytest
119

1210
from pandas.compat import (
1311
IS64,
14-
is_platform_arm,
15-
is_platform_power,
16-
is_platform_riscv64,
1712
)
1813
from pandas.errors import Pandas4Warning
1914

@@ -1084,48 +1079,136 @@ def test_rolling_sem(frame_or_series):
10841079
expected = Series([np.nan] + [0.7071067811865476] * 2)
10851080
tm.assert_series_equal(result, expected)
10861081

1082+
10871083
@pytest.mark.parametrize(
1088-
("func", "values", "window", "ddof", "exp_value"),
1089-
[
1090-
("var", [2.72993945, 1.58444294, 4.14371708, 4.92961687, 2.7138744 ,3.48168586, 0.69505519, 1.87511994, 4.20167276, 0.04797675], 3, 1, "numpy_compute"),
1091-
("std", [2.72993945, 1.58444294, 4.14371708, 4.92961687, 2.7138744 ,3.48168586, 0.69505519, 1.87511994, 4.20167276, 0.04797675], 3, 1, "numpy_compute"),
1092-
("var", [2.72993945, 1.58444294, 4.14371708, 4.92961687, 2.7138744 ,3.48168586, 0.69505519, 1.87511994, 4.20167276, 0.04797675], 2, 1, "numpy_compute"),
1093-
("std", [2.72993945, 1.58444294, 4.14371708, 4.92961687, 2.7138744 ,3.48168586, 0.69505519, 1.87511994, 4.20167276, 0.04797675], 2, 1, "numpy_compute"),
1094-
("var", [99999999999999999, 1, 1, 2, 3, 1, 1], 2, 1, 0),
1095-
("std", [99999999999999999, 1, 1, 2, 3, 1, 1], 2, 1, 0),
1096-
("var", [99999999999999999, 1, 2, 2, 3, 1, 1], 2, 1, 0),
1097-
("var", [99999999999999999, 1, 2, 2, 3, 1, 1], 2, 1, 0),
1098-
("var", [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0], 5, 0, "numpy_compute"),
1099-
],
1084+
("func", "values", "window", "ddof", "exp_value"),
1085+
[
1086+
(
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,
1101+
1,
1102+
"numpy_compute",
1103+
),
1104+
(
1105+
"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,
1119+
1,
1120+
"numpy_compute",
1121+
),
1122+
(
1123+
"var",
1124+
[
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,
1135+
],
1136+
2,
1137+
1,
1138+
"numpy_compute",
1139+
),
1140+
(
1141+
"std",
1142+
[
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,
1153+
],
1154+
2,
1155+
1,
1156+
"numpy_compute",
1157+
),
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"),
1163+
],
11001164
)
11011165
def test_rolling_var_correctness(func, values, window, ddof, exp_value):
11021166
# This tests subsume the previous tests under test_rolling_var_numerical_issues
11031167
# GH: 37051, 42064, 54333
11041168
ts = Series(values)
11051169
result = getattr(ts.rolling(window=window, center=True), func)(ddof=ddof)
11061170
if result.last_valid_index():
1107-
result = result[result.first_valid_index() : result.last_valid_index()+1].reset_index(drop=True)
1108-
expected = Series(getattr(sliding_window_view(values, window_shape=window), func)(axis=-1, ddof=ddof)) #.var(axis=-1, ddof=ddof))
1171+
result = result[
1172+
result.first_valid_index() : result.last_valid_index() + 1
1173+
].reset_index(drop=True)
1174+
expected = Series(
1175+
getattr(sliding_window_view(values, window_shape=window), func)(
1176+
axis=-1, ddof=ddof
1177+
)
1178+
)
11091179
tm.assert_series_equal(result, expected, atol=1e-55)
11101180
# GH 42064
11111181
if exp_value == 0:
1112-
# new `roll_var` will output 0.0 correctly
1113-
tm.assert_series_equal(result==0, expected==0)
1182+
# new `roll_var` will output 0.0 correctly
1183+
tm.assert_series_equal(result == 0, expected == 0)
1184+
11141185

11151186
def test_rolling_var_numerical_stability():
11161187
# GH 52407
1117-
A = [0.00000000e+00, 0.00000000e+00, 3.16188252e-18, 2.95781651e-16,
1118-
2.23153542e-51, 0.00000000e+00, 0.00000000e+00, 5.39943432e-48,
1119-
1.38206260e-73, 0.00000000e+00]
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+
]
11201200
ts = Series(A)
11211201

11221202
result = ts.rolling(window=3, center=True).var(ddof=1)
1123-
result = result[result.first_valid_index() : result.last_valid_index()+1].reset_index(drop=True)
1124-
1203+
result = result[
1204+
result.first_valid_index() : result.last_valid_index() + 1
1205+
].reset_index(drop=True)
1206+
11251207
# numpy implementation
11261208
expected = Series(sliding_window_view(A, window_shape=3).var(axis=-1, ddof=1))
11271209
tm.assert_series_equal(result, expected, atol=1e-55)
11281210

1211+
11291212
def test_timeoffset_as_window_parameter_for_corr(unit):
11301213
# GH: 28266
11311214
dti = DatetimeIndex(

0 commit comments

Comments
 (0)