Skip to content

Commit 6b826f2

Browse files
committed
restore
1 parent 8f15422 commit 6b826f2

23 files changed

+9772
-0
lines changed

pandas/tests/window/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import pytest
2+
3+
pytestmark = [
4+
# 2021-02-01 needed until numba updates their usage
5+
pytest.mark.filterwarnings(
6+
r"ignore:`np\.int` is a deprecated alias:DeprecationWarning"
7+
),
8+
]

pandas/tests/window/conftest.py

Lines changed: 261 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,261 @@
1+
from datetime import (
2+
datetime,
3+
timedelta,
4+
)
5+
6+
import numpy as np
7+
import pytest
8+
9+
import pandas.util._test_decorators as td
10+
11+
from pandas import (
12+
DataFrame,
13+
Series,
14+
bdate_range,
15+
to_datetime,
16+
)
17+
18+
19+
@pytest.fixture(params=[True, False])
20+
def raw(request):
21+
"""raw keyword argument for rolling.apply"""
22+
return request.param
23+
24+
25+
@pytest.fixture(
26+
params=[
27+
"triang",
28+
"blackman",
29+
"hamming",
30+
"bartlett",
31+
"bohman",
32+
"blackmanharris",
33+
"nuttall",
34+
"barthann",
35+
]
36+
)
37+
def win_types(request):
38+
return request.param
39+
40+
41+
@pytest.fixture(params=["kaiser", "gaussian", "general_gaussian", "exponential"])
42+
def win_types_special(request):
43+
return request.param
44+
45+
46+
@pytest.fixture(
47+
params=[
48+
"sum",
49+
"mean",
50+
"median",
51+
"max",
52+
"min",
53+
"var",
54+
"std",
55+
"kurt",
56+
"skew",
57+
"count",
58+
"sem",
59+
]
60+
)
61+
def arithmetic_win_operators(request):
62+
return request.param
63+
64+
65+
@pytest.fixture(
66+
params=[
67+
["sum", {}],
68+
["mean", {}],
69+
["median", {}],
70+
["max", {}],
71+
["min", {}],
72+
["var", {}],
73+
["var", {"ddof": 0}],
74+
["std", {}],
75+
["std", {"ddof": 0}],
76+
]
77+
)
78+
def arithmetic_numba_supported_operators(request):
79+
return request.param
80+
81+
82+
@pytest.fixture(params=["right", "left", "both", "neither"])
83+
def closed(request):
84+
return request.param
85+
86+
87+
@pytest.fixture(params=[True, False])
88+
def center(request):
89+
return request.param
90+
91+
92+
@pytest.fixture(params=[None, 1])
93+
def min_periods(request):
94+
return request.param
95+
96+
97+
@pytest.fixture(params=["single", "table"])
98+
def method(request):
99+
"""method keyword in rolling/expanding/ewm constructor"""
100+
return request.param
101+
102+
103+
@pytest.fixture(params=[True, False])
104+
def parallel(request):
105+
"""parallel keyword argument for numba.jit"""
106+
return request.param
107+
108+
109+
# Can parameterize nogil & nopython over True | False, but limiting per
110+
# https://github.com/pandas-dev/pandas/pull/41971#issuecomment-860607472
111+
112+
113+
@pytest.fixture(params=[False])
114+
def nogil(request):
115+
"""nogil keyword argument for numba.jit"""
116+
return request.param
117+
118+
119+
@pytest.fixture(params=[True])
120+
def nopython(request):
121+
"""nopython keyword argument for numba.jit"""
122+
return request.param
123+
124+
125+
@pytest.fixture(params=[True, False])
126+
def adjust(request):
127+
"""adjust keyword argument for ewm"""
128+
return request.param
129+
130+
131+
@pytest.fixture(params=[True, False])
132+
def ignore_na(request):
133+
"""ignore_na keyword argument for ewm"""
134+
return request.param
135+
136+
137+
@pytest.fixture(params=[pytest.param("numba", marks=td.skip_if_no("numba")), "cython"])
138+
def engine(request):
139+
"""engine keyword argument for rolling.apply"""
140+
return request.param
141+
142+
143+
@pytest.fixture(
144+
params=[
145+
pytest.param(("numba", True), marks=td.skip_if_no("numba")),
146+
("cython", True),
147+
("cython", False),
148+
]
149+
)
150+
def engine_and_raw(request):
151+
"""engine and raw keyword arguments for rolling.apply"""
152+
return request.param
153+
154+
155+
@pytest.fixture
156+
def times_frame():
157+
"""Frame for testing times argument in EWM groupby."""
158+
return DataFrame(
159+
{
160+
"A": ["a", "b", "c", "a", "b", "c", "a", "b", "c", "a"],
161+
"B": [0, 0, 0, 1, 1, 1, 2, 2, 2, 3],
162+
"C": to_datetime(
163+
[
164+
"2020-01-01",
165+
"2020-01-01",
166+
"2020-01-01",
167+
"2020-01-02",
168+
"2020-01-10",
169+
"2020-01-22",
170+
"2020-01-03",
171+
"2020-01-23",
172+
"2020-01-23",
173+
"2020-01-04",
174+
]
175+
),
176+
}
177+
)
178+
179+
180+
@pytest.fixture(params=["1 day", timedelta(days=1)])
181+
def halflife_with_times(request):
182+
"""Halflife argument for EWM when times is specified."""
183+
return request.param
184+
185+
186+
@pytest.fixture(
187+
params=[
188+
"object",
189+
"category",
190+
"int8",
191+
"int16",
192+
"int32",
193+
"int64",
194+
"uint8",
195+
"uint16",
196+
"uint32",
197+
"uint64",
198+
"float16",
199+
"float32",
200+
"float64",
201+
"m8[ns]",
202+
"M8[ns]",
203+
"datetime64[ns, UTC]",
204+
]
205+
)
206+
def dtypes(request):
207+
"""Dtypes for window tests"""
208+
return request.param
209+
210+
211+
@pytest.fixture(
212+
params=[
213+
DataFrame([[2, 4], [1, 2], [5, 2], [8, 1]], columns=[1, 0]),
214+
DataFrame([[2, 4], [1, 2], [5, 2], [8, 1]], columns=[1, 1]),
215+
DataFrame([[2, 4], [1, 2], [5, 2], [8, 1]], columns=["C", "C"]),
216+
DataFrame([[2, 4], [1, 2], [5, 2], [8, 1]], columns=[1.0, 0]),
217+
DataFrame([[2, 4], [1, 2], [5, 2], [8, 1]], columns=[0.0, 1]),
218+
DataFrame([[2, 4], [1, 2], [5, 2], [8, 1]], columns=["C", 1]),
219+
DataFrame([[2.0, 4.0], [1.0, 2.0], [5.0, 2.0], [8.0, 1.0]], columns=[1, 0.0]),
220+
DataFrame([[2, 4.0], [1, 2.0], [5, 2.0], [8, 1.0]], columns=[0, 1.0]),
221+
DataFrame([[2, 4], [1, 2], [5, 2], [8, 1.0]], columns=[1.0, "X"]),
222+
]
223+
)
224+
def pairwise_frames(request):
225+
"""Pairwise frames test_pairwise"""
226+
return request.param
227+
228+
229+
@pytest.fixture
230+
def pairwise_target_frame():
231+
"""Pairwise target frame for test_pairwise"""
232+
return DataFrame([[2, 4], [1, 2], [5, 2], [8, 1]], columns=[0, 1])
233+
234+
235+
@pytest.fixture
236+
def pairwise_other_frame():
237+
"""Pairwise other frame for test_pairwise"""
238+
return DataFrame(
239+
[[None, 1, 1], [None, 1, 2], [None, 3, 2], [None, 8, 1]],
240+
columns=["Y", "Z", "X"],
241+
)
242+
243+
244+
@pytest.fixture
245+
def series():
246+
"""Make mocked series as fixture."""
247+
arr = np.random.randn(100)
248+
locs = np.arange(20, 40)
249+
arr[locs] = np.NaN
250+
series = Series(arr, index=bdate_range(datetime(2009, 1, 1), periods=100))
251+
return series
252+
253+
254+
@pytest.fixture
255+
def frame():
256+
"""Make mocked frame as fixture."""
257+
return DataFrame(
258+
np.random.randn(100, 10),
259+
index=bdate_range(datetime(2009, 1, 1), periods=100),
260+
columns=np.arange(10),
261+
)

pandas/tests/window/moments/__init__.py

Whitespace-only changes.
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import itertools
2+
3+
import numpy as np
4+
import pytest
5+
6+
from pandas import (
7+
DataFrame,
8+
Series,
9+
notna,
10+
)
11+
12+
13+
def create_series():
14+
return [
15+
Series(dtype=np.float64, name="a"),
16+
Series([np.nan] * 5),
17+
Series([1.0] * 5),
18+
Series(range(5, 0, -1)),
19+
Series(range(5)),
20+
Series([np.nan, 1.0, np.nan, 1.0, 1.0]),
21+
Series([np.nan, 1.0, np.nan, 2.0, 3.0]),
22+
Series([np.nan, 1.0, np.nan, 3.0, 2.0]),
23+
]
24+
25+
26+
def create_dataframes():
27+
return [
28+
DataFrame(columns=["a", "a"]),
29+
DataFrame(np.arange(15).reshape((5, 3)), columns=["a", "a", 99]),
30+
] + [DataFrame(s) for s in create_series()]
31+
32+
33+
def is_constant(x):
34+
values = x.values.ravel("K")
35+
return len(set(values[notna(values)])) == 1
36+
37+
38+
@pytest.fixture(
39+
params=(
40+
obj
41+
for obj in itertools.chain(create_series(), create_dataframes())
42+
if is_constant(obj)
43+
),
44+
scope="module",
45+
)
46+
def consistent_data(request):
47+
return request.param
48+
49+
50+
@pytest.fixture(params=create_series())
51+
def series_data(request):
52+
return request.param
53+
54+
55+
@pytest.fixture(params=itertools.chain(create_series(), create_dataframes()))
56+
def all_data(request):
57+
"""
58+
Test:
59+
- Empty Series / DataFrame
60+
- All NaN
61+
- All consistent value
62+
- Monotonically decreasing
63+
- Monotonically increasing
64+
- Monotonically consistent with NaNs
65+
- Monotonically increasing with NaNs
66+
- Monotonically decreasing with NaNs
67+
"""
68+
return request.param
69+
70+
71+
@pytest.fixture(params=[(1, 0), (5, 1)])
72+
def rolling_consistency_cases(request):
73+
"""window, min_periods"""
74+
return request.param
75+
76+
77+
@pytest.fixture(params=[0, 2])
78+
def min_periods(request):
79+
return request.param

0 commit comments

Comments
 (0)