Skip to content

Commit befc6b5

Browse files
mroeschkeyehoshuadimarsky
authored andcommitted
TST: Move once-used fixtures to specific files: (pandas-dev#45674)
1 parent cb602ec commit befc6b5

10 files changed

+135
-141
lines changed

pandas/tests/window/conftest.py

-133
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
DataFrame,
1313
Series,
1414
bdate_range,
15-
to_datetime,
1615
)
1716

1817

@@ -22,27 +21,6 @@ def raw(request):
2221
return request.param
2322

2423

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-
4624
@pytest.fixture(
4725
params=[
4826
"sum",
@@ -62,28 +40,6 @@ def arithmetic_win_operators(request):
6240
return request.param
6341

6442

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-
8743
@pytest.fixture(params=[True, False])
8844
def center(request):
8945
return request.param
@@ -94,12 +50,6 @@ def min_periods(request):
9450
return request.param
9551

9652

97-
@pytest.fixture(params=["single", "table"])
98-
def method(request):
99-
"""method keyword in rolling/expanding/ewm constructor"""
100-
return request.param
101-
102-
10353
@pytest.fixture(params=[True, False])
10454
def parallel(request):
10555
"""parallel keyword argument for numba.jit"""
@@ -152,95 +102,12 @@ def engine_and_raw(request):
152102
return request.param
153103

154104

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-
180105
@pytest.fixture(params=["1 day", timedelta(days=1)])
181106
def halflife_with_times(request):
182107
"""Halflife argument for EWM when times is specified."""
183108
return request.param
184109

185110

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-
244111
@pytest.fixture
245112
def series():
246113
"""Make mocked series as fixture."""

pandas/tests/window/moments/conftest.py

-7
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ def is_constant(x):
4141
for obj in itertools.chain(create_series(), create_dataframes())
4242
if is_constant(obj)
4343
),
44-
scope="module",
4544
)
4645
def consistent_data(request):
4746
return request.param
@@ -68,12 +67,6 @@ def all_data(request):
6867
return request.param
6968

7069

71-
@pytest.fixture(params=[(1, 0), (5, 1)])
72-
def rolling_consistency_cases(request):
73-
"""window, min_periods"""
74-
return request.param
75-
76-
7770
@pytest.fixture(params=[0, 2])
7871
def min_periods(request):
7972
return request.param

pandas/tests/window/moments/test_moments_consistency_rolling.py

+6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ def all_na(x):
1313
return x.isnull().all().all()
1414

1515

16+
@pytest.fixture(params=[(1, 0), (5, 1)])
17+
def rolling_consistency_cases(request):
18+
"""window, min_periods"""
19+
return request.param
20+
21+
1622
@pytest.mark.parametrize("f", [lambda v: Series(v).sum(), np.nansum, np.sum])
1723
def test_rolling_apply_consistency_sum(
1824
request, all_data, rolling_consistency_cases, center, f

pandas/tests/window/test_dtypes.py

+25
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,31 @@ def get_dtype(dtype, coerce_int=None):
2424
return pandas_dtype(dtype)
2525

2626

27+
@pytest.fixture(
28+
params=[
29+
"object",
30+
"category",
31+
"int8",
32+
"int16",
33+
"int32",
34+
"int64",
35+
"uint8",
36+
"uint16",
37+
"uint32",
38+
"uint64",
39+
"float16",
40+
"float32",
41+
"float64",
42+
"m8[ns]",
43+
"M8[ns]",
44+
"datetime64[ns, UTC]",
45+
]
46+
)
47+
def dtypes(request):
48+
"""Dtypes for window tests"""
49+
return request.param
50+
51+
2752
@pytest.mark.parametrize(
2853
"method, data, expected_data, coerce_int, min_periods",
2954
[

pandas/tests/window/test_groupby.py

+25
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,31 @@
1515
from pandas.core.groupby.groupby import get_groupby
1616

1717

18+
@pytest.fixture
19+
def times_frame():
20+
"""Frame for testing times argument in EWM groupby."""
21+
return DataFrame(
22+
{
23+
"A": ["a", "b", "c", "a", "b", "c", "a", "b", "c", "a"],
24+
"B": [0, 0, 0, 1, 1, 1, 2, 2, 2, 3],
25+
"C": to_datetime(
26+
[
27+
"2020-01-01",
28+
"2020-01-01",
29+
"2020-01-01",
30+
"2020-01-02",
31+
"2020-01-10",
32+
"2020-01-22",
33+
"2020-01-03",
34+
"2020-01-23",
35+
"2020-01-23",
36+
"2020-01-04",
37+
]
38+
),
39+
}
40+
)
41+
42+
1843
class TestRolling:
1944
def setup_method(self):
2045
self.frame = DataFrame({"A": [1] * 20 + [2] * 12 + [3] * 8, "B": np.arange(40)})

pandas/tests/window/test_numba.py

+23
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,29 @@
1414
from pandas.core.util.numba_ import NUMBA_FUNC_CACHE
1515

1616

17+
@pytest.fixture(params=["single", "table"])
18+
def method(request):
19+
"""method keyword in rolling/expanding/ewm constructor"""
20+
return request.param
21+
22+
23+
@pytest.fixture(
24+
params=[
25+
["sum", {}],
26+
["mean", {}],
27+
["median", {}],
28+
["max", {}],
29+
["min", {}],
30+
["var", {}],
31+
["var", {"ddof": 0}],
32+
["std", {}],
33+
["std", {"ddof": 0}],
34+
]
35+
)
36+
def arithmetic_numba_supported_operators(request):
37+
return request.param
38+
39+
1740
@td.skip_if_no("numba")
1841
@pytest.mark.filterwarnings("ignore:\n")
1942
# Filter warnings when parallel=True and the function can't be parallelized by Numba

pandas/tests/window/test_pairwise.py

+33
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,39 @@
1414
from pandas.core.algorithms import safe_sort
1515

1616

17+
@pytest.fixture(
18+
params=[
19+
DataFrame([[2, 4], [1, 2], [5, 2], [8, 1]], columns=[1, 0]),
20+
DataFrame([[2, 4], [1, 2], [5, 2], [8, 1]], columns=[1, 1]),
21+
DataFrame([[2, 4], [1, 2], [5, 2], [8, 1]], columns=["C", "C"]),
22+
DataFrame([[2, 4], [1, 2], [5, 2], [8, 1]], columns=[1.0, 0]),
23+
DataFrame([[2, 4], [1, 2], [5, 2], [8, 1]], columns=[0.0, 1]),
24+
DataFrame([[2, 4], [1, 2], [5, 2], [8, 1]], columns=["C", 1]),
25+
DataFrame([[2.0, 4.0], [1.0, 2.0], [5.0, 2.0], [8.0, 1.0]], columns=[1, 0.0]),
26+
DataFrame([[2, 4.0], [1, 2.0], [5, 2.0], [8, 1.0]], columns=[0, 1.0]),
27+
DataFrame([[2, 4], [1, 2], [5, 2], [8, 1.0]], columns=[1.0, "X"]),
28+
]
29+
)
30+
def pairwise_frames(request):
31+
"""Pairwise frames test_pairwise"""
32+
return request.param
33+
34+
35+
@pytest.fixture
36+
def pairwise_target_frame():
37+
"""Pairwise target frame for test_pairwise"""
38+
return DataFrame([[2, 4], [1, 2], [5, 2], [8, 1]], columns=[0, 1])
39+
40+
41+
@pytest.fixture
42+
def pairwise_other_frame():
43+
"""Pairwise other frame for test_pairwise"""
44+
return DataFrame(
45+
[[None, 1, 1], [None, 1, 2], [None, 3, 2], [None, 8, 1]],
46+
columns=["Y", "Z", "X"],
47+
)
48+
49+
1750
def test_rolling_cov(series):
1851
A = series
1952
B = A + np.random.randn(len(A))

pandas/tests/window/test_rolling.py

+1
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ def test_numpy_compat(method):
132132
getattr(r, method)(dtype=np.float64)
133133

134134

135+
@pytest.mark.parametrize("closed", ["right", "left", "both", "neither"])
135136
def test_closed_fixed(closed, arithmetic_win_operators):
136137
# GH 34315
137138
func_name = arithmetic_win_operators

pandas/tests/window/test_timeseries_window.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class TestRollingTS:
2020
# rolling time-series friendly
2121
# xref GH13327
2222

23-
def setup_method(self, method):
23+
def setup_method(self):
2424

2525
self.regular = DataFrame(
2626
{"A": date_range("20130101", periods=5, freq="s"), "B": range(5)}

pandas/tests/window/test_win_type.py

+21
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,27 @@
1515
from pandas.api.indexers import BaseIndexer
1616

1717

18+
@pytest.fixture(
19+
params=[
20+
"triang",
21+
"blackman",
22+
"hamming",
23+
"bartlett",
24+
"bohman",
25+
"blackmanharris",
26+
"nuttall",
27+
"barthann",
28+
]
29+
)
30+
def win_types(request):
31+
return request.param
32+
33+
34+
@pytest.fixture(params=["kaiser", "gaussian", "general_gaussian", "exponential"])
35+
def win_types_special(request):
36+
return request.param
37+
38+
1839
@td.skip_if_no_scipy
1940
def test_constructor(frame_or_series):
2041
# GH 12669

0 commit comments

Comments
 (0)