Skip to content

Commit dffa51f

Browse files
authored
TST/CLN: Reuse top level fixtures instead of parametrizations (#56583)
* Clean up axis fixtures * Use top level dropna/observed fixture * Use top level sort fixture * Use top level sort fixture * Use top level skipna fixture * Use top level keep fixture * Use top level closed fixture * Use top level writable fixture * Use top level other_closed * Use top level join_type fixture * use another join_type * Use another join_type * use top level nselect_method * Reuse all_boolean_reductions * reuse all_numeric_accumulations * Use shared na_action fixture * Use top level ascending fixture * Use shared rank_method fixture * Use shared as_index fixture * Share more fixtures * Reuse orient fixture * Use shared cache fixture * Move nogil, parallel, nopython to top level * Use top level center * Reuse more fixtures * Fix errors
1 parent 471690f commit dffa51f

File tree

114 files changed

+307
-560
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+307
-560
lines changed

pandas/conftest.py

+84-23
Original file line numberDiff line numberDiff line change
@@ -281,17 +281,6 @@ def axis(request):
281281
return request.param
282282

283283

284-
axis_frame = axis
285-
286-
287-
@pytest.fixture(params=[1, "columns"], ids=lambda x: f"axis={repr(x)}")
288-
def axis_1(request):
289-
"""
290-
Fixture for returning aliases of axis 1 of a DataFrame.
291-
"""
292-
return request.param
293-
294-
295284
@pytest.fixture(params=[True, False, None])
296285
def observed(request):
297286
"""
@@ -313,6 +302,22 @@ def ordered(request):
313302
return request.param
314303

315304

305+
@pytest.fixture(params=[True, False])
306+
def dropna(request):
307+
"""
308+
Boolean 'dropna' parameter.
309+
"""
310+
return request.param
311+
312+
313+
@pytest.fixture(params=[True, False])
314+
def sort(request):
315+
"""
316+
Boolean 'sort' parameter.
317+
"""
318+
return request.param
319+
320+
316321
@pytest.fixture(params=[True, False])
317322
def skipna(request):
318323
"""
@@ -414,6 +419,74 @@ def nselect_method(request):
414419
return request.param
415420

416421

422+
@pytest.fixture(params=[None, "ignore"])
423+
def na_action(request):
424+
"""
425+
Fixture for 'na_action' argument in map.
426+
"""
427+
return request.param
428+
429+
430+
@pytest.fixture(params=[True, False])
431+
def ascending(request):
432+
"""
433+
Fixture for 'na_action' argument in sort_values/sort_index/rank.
434+
"""
435+
return request.param
436+
437+
438+
@pytest.fixture(params=["average", "min", "max", "first", "dense"])
439+
def rank_method(request):
440+
"""
441+
Fixture for 'rank' argument in rank.
442+
"""
443+
return request.param
444+
445+
446+
@pytest.fixture(params=[True, False])
447+
def as_index(request):
448+
"""
449+
Fixture for 'as_index' argument in groupby.
450+
"""
451+
return request.param
452+
453+
454+
@pytest.fixture(params=[True, False])
455+
def cache(request):
456+
"""
457+
Fixture for 'cache' argument in to_datetime.
458+
"""
459+
return request.param
460+
461+
462+
@pytest.fixture(params=[True, False])
463+
def parallel(request):
464+
"""
465+
Fixture for parallel keyword argument for numba.jit.
466+
"""
467+
return request.param
468+
469+
470+
# Can parameterize nogil & nopython over True | False, but limiting per
471+
# https://github.com/pandas-dev/pandas/pull/41971#issuecomment-860607472
472+
473+
474+
@pytest.fixture(params=[False])
475+
def nogil(request):
476+
"""
477+
Fixture for nogil keyword argument for numba.jit.
478+
"""
479+
return request.param
480+
481+
482+
@pytest.fixture(params=[True])
483+
def nopython(request):
484+
"""
485+
Fixture for nopython keyword argument for numba.jit.
486+
"""
487+
return request.param
488+
489+
417490
# ----------------------------------------------------------------
418491
# Missing values & co.
419492
# ----------------------------------------------------------------
@@ -478,10 +551,6 @@ def index_or_series(request):
478551
return request.param
479552

480553

481-
# Generate cartesian product of index_or_series fixture:
482-
index_or_series2 = index_or_series
483-
484-
485554
@pytest.fixture(params=[Index, Series, pd.array], ids=["index", "series", "array"])
486555
def index_or_series_or_array(request):
487556
"""
@@ -674,10 +743,6 @@ def index(request):
674743
return indices_dict[request.param].copy()
675744

676745

677-
# Needed to generate cartesian product of indices
678-
index_fixture2 = index
679-
680-
681746
@pytest.fixture(
682747
params=[
683748
key for key, value in indices_dict.items() if not isinstance(value, MultiIndex)
@@ -691,10 +756,6 @@ def index_flat(request):
691756
return indices_dict[key].copy()
692757

693758

694-
# Alias so we can test with cartesian product of index_flat
695-
index_flat2 = index_flat
696-
697-
698759
@pytest.fixture(
699760
params=[
700761
key

pandas/tests/apply/test_str.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,9 @@ def test_apply_with_string_funcs(request, float_frame, func, args, kwds, how):
4343
tm.assert_series_equal(result, expected)
4444

4545

46-
@pytest.mark.parametrize("arg", ["sum", "mean", "min", "max", "std"])
47-
def test_with_string_args(datetime_series, arg):
48-
result = datetime_series.apply(arg)
49-
expected = getattr(datetime_series, arg)()
46+
def test_with_string_args(datetime_series, all_numeric_reductions):
47+
result = datetime_series.apply(all_numeric_reductions)
48+
expected = getattr(datetime_series, all_numeric_reductions)()
5049
assert result == expected
5150

5251

pandas/tests/arithmetic/test_datetime64.py

-4
Original file line numberDiff line numberDiff line change
@@ -1221,7 +1221,6 @@ class TestDatetime64DateOffsetArithmetic:
12211221
# Tick DateOffsets
12221222

12231223
# TODO: parametrize over timezone?
1224-
@pytest.mark.parametrize("unit", ["s", "ms", "us", "ns"])
12251224
def test_dt64arr_series_add_tick_DateOffset(self, box_with_array, unit):
12261225
# GH#4532
12271226
# operate with pd.offsets
@@ -1311,7 +1310,6 @@ def test_dti_add_tick_tzaware(self, tz_aware_fixture, box_with_array):
13111310
# -------------------------------------------------------------
13121311
# RelativeDelta DateOffsets
13131312

1314-
@pytest.mark.parametrize("unit", ["s", "ms", "us", "ns"])
13151313
def test_dt64arr_add_sub_relativedelta_offsets(self, box_with_array, unit):
13161314
# GH#10699
13171315
vec = DatetimeIndex(
@@ -1422,7 +1420,6 @@ def test_dt64arr_add_sub_relativedelta_offsets(self, box_with_array, unit):
14221420
)
14231421
@pytest.mark.parametrize("normalize", [True, False])
14241422
@pytest.mark.parametrize("n", [0, 5])
1425-
@pytest.mark.parametrize("unit", ["s", "ms", "us", "ns"])
14261423
@pytest.mark.parametrize("tz", [None, "US/Central"])
14271424
def test_dt64arr_add_sub_DateOffsets(
14281425
self, box_with_array, n, normalize, cls_and_kwargs, unit, tz
@@ -2356,7 +2353,6 @@ def test_dti_addsub_object_arraylike(
23562353

23572354
@pytest.mark.parametrize("years", [-1, 0, 1])
23582355
@pytest.mark.parametrize("months", [-2, 0, 2])
2359-
@pytest.mark.parametrize("unit", ["s", "ms", "us", "ns"])
23602356
def test_shift_months(years, months, unit):
23612357
dti = DatetimeIndex(
23622358
[

pandas/tests/arrays/boolean/test_reduction.py

-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ def test_any_all(values, exp_any, exp_all, exp_any_noskip, exp_all_noskip):
4343
assert np.all(a.all()) is exp_all
4444

4545

46-
@pytest.mark.parametrize("dropna", [True, False])
4746
def test_reductions_return_types(dropna, data, all_numeric_reductions):
4847
op = all_numeric_reductions
4948
s = pd.Series(data)

pandas/tests/arrays/categorical/test_algos.py

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import pandas._testing as tm
66

77

8-
@pytest.mark.parametrize("ordered", [True, False])
98
@pytest.mark.parametrize("categories", [["b", "a", "c"], ["a", "b", "c", "d"]])
109
def test_factorize(categories, ordered):
1110
cat = pd.Categorical(

pandas/tests/arrays/categorical/test_analytics.py

-2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ def test_min_max_ordered_empty(self, categories, expected, aggregation):
9797
"values, categories",
9898
[(["a", "b", "c", np.nan], list("cba")), ([1, 2, 3, np.nan], [3, 2, 1])],
9999
)
100-
@pytest.mark.parametrize("skipna", [True, False])
101100
@pytest.mark.parametrize("function", ["min", "max"])
102101
def test_min_max_with_nan(self, values, categories, function, skipna):
103102
# GH 25303
@@ -111,7 +110,6 @@ def test_min_max_with_nan(self, values, categories, function, skipna):
111110
assert result == expected
112111

113112
@pytest.mark.parametrize("function", ["min", "max"])
114-
@pytest.mark.parametrize("skipna", [True, False])
115113
def test_min_max_only_nan(self, function, skipna):
116114
# https://github.com/pandas-dev/pandas/issues/33450
117115
cat = Categorical([np.nan], categories=[1, 2], ordered=True)

pandas/tests/arrays/categorical/test_api.py

-1
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,6 @@ def test_set_categories(self):
301301
(["a", "b", "c"], ["a", "b"], ["d", "e"]),
302302
],
303303
)
304-
@pytest.mark.parametrize("ordered", [True, False])
305304
def test_set_categories_many(self, values, categories, new_categories, ordered):
306305
c = Categorical(values, categories)
307306
expected = Categorical(values, new_categories, ordered)

pandas/tests/arrays/categorical/test_astype.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ def test_astype_str_int_categories_to_nullable_float(self):
8181
expected = array(codes, dtype="Float64") / 2
8282
tm.assert_extension_array_equal(res, expected)
8383

84-
@pytest.mark.parametrize("ordered", [True, False])
8584
def test_astype(self, ordered):
8685
# string
8786
cat = Categorical(list("abbaaccc"), ordered=ordered)
@@ -108,11 +107,10 @@ def test_astype(self, ordered):
108107
tm.assert_numpy_array_equal(result, expected)
109108

110109
@pytest.mark.parametrize("dtype_ordered", [True, False])
111-
@pytest.mark.parametrize("cat_ordered", [True, False])
112-
def test_astype_category(self, dtype_ordered, cat_ordered):
110+
def test_astype_category(self, dtype_ordered, ordered):
113111
# GH#10696/GH#18593
114112
data = list("abcaacbab")
115-
cat = Categorical(data, categories=list("bac"), ordered=cat_ordered)
113+
cat = Categorical(data, categories=list("bac"), ordered=ordered)
116114

117115
# standard categories
118116
dtype = CategoricalDtype(ordered=dtype_ordered)

pandas/tests/arrays/categorical/test_constructors.py

-2
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,6 @@ def test_constructor_dtype_and_others_raises(self):
437437
Categorical(["a", "b"], ordered=False, dtype=dtype)
438438

439439
@pytest.mark.parametrize("categories", [None, ["a", "b"], ["a", "c"]])
440-
@pytest.mark.parametrize("ordered", [True, False])
441440
def test_constructor_str_category(self, categories, ordered):
442441
result = Categorical(
443442
["a", "b"], categories=categories, ordered=ordered, dtype="category"
@@ -683,7 +682,6 @@ def test_from_inferred_categories_coerces(self):
683682
expected = Categorical([1, 1, 2, np.nan])
684683
tm.assert_categorical_equal(result, expected)
685684

686-
@pytest.mark.parametrize("ordered", [None, True, False])
687685
def test_construction_with_ordered(self, ordered):
688686
# GH 9347, 9190
689687
cat = Categorical([0, 1, 2], ordered=ordered)

pandas/tests/arrays/categorical/test_dtypes.py

-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ def test_set_dtype_new_categories(self):
8383
(["a", "b", "c"], ["a", "b"], ["d", "e"]),
8484
],
8585
)
86-
@pytest.mark.parametrize("ordered", [True, False])
8786
def test_set_dtype_many(self, values, categories, new_categories, ordered):
8887
c = Categorical(values, categories)
8988
expected = Categorical(values, new_categories, ordered)

pandas/tests/arrays/categorical/test_map.py

-5
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@
1010
import pandas._testing as tm
1111

1212

13-
@pytest.fixture(params=[None, "ignore"])
14-
def na_action(request):
15-
return request.param
16-
17-
1813
@pytest.mark.parametrize(
1914
"data, categories",
2015
[

pandas/tests/arrays/datetimes/test_constructors.py

-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ def test_copy(self):
165165
arr = DatetimeArray._from_sequence(data, copy=True)
166166
assert arr._ndarray is not data
167167

168-
@pytest.mark.parametrize("unit", ["s", "ms", "us", "ns"])
169168
def test_numpy_datetime_unit(self, unit):
170169
data = np.array([1, 2, 3], dtype=f"M8[{unit}]")
171170
arr = DatetimeArray._from_sequence(data)

pandas/tests/arrays/datetimes/test_reductions.py

-7
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010

1111

1212
class TestReductions:
13-
@pytest.fixture(params=["s", "ms", "us", "ns"])
14-
def unit(self, request):
15-
return request.param
16-
1713
@pytest.fixture
1814
def arr1d(self, tz_naive_fixture):
1915
"""Fixture returning DatetimeArray with parametrized timezones"""
@@ -54,7 +50,6 @@ def test_min_max(self, arr1d, unit):
5450
assert result is NaT
5551

5652
@pytest.mark.parametrize("tz", [None, "US/Central"])
57-
@pytest.mark.parametrize("skipna", [True, False])
5853
def test_min_max_empty(self, skipna, tz):
5954
dtype = DatetimeTZDtype(tz=tz) if tz is not None else np.dtype("M8[ns]")
6055
arr = DatetimeArray._from_sequence([], dtype=dtype)
@@ -65,7 +60,6 @@ def test_min_max_empty(self, skipna, tz):
6560
assert result is NaT
6661

6762
@pytest.mark.parametrize("tz", [None, "US/Central"])
68-
@pytest.mark.parametrize("skipna", [True, False])
6963
def test_median_empty(self, skipna, tz):
7064
dtype = DatetimeTZDtype(tz=tz) if tz is not None else np.dtype("M8[ns]")
7165
arr = DatetimeArray._from_sequence([], dtype=dtype)
@@ -164,7 +158,6 @@ def test_mean_2d(self):
164158
expected = dti.mean()
165159
assert result == expected
166160

167-
@pytest.mark.parametrize("skipna", [True, False])
168161
def test_mean_empty(self, arr1d, skipna):
169162
arr = arr1d[:0]
170163

pandas/tests/arrays/floating/test_function.py

-3
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ def test_value_counts_with_normalize():
127127
tm.assert_series_equal(result, expected)
128128

129129

130-
@pytest.mark.parametrize("skipna", [True, False])
131130
@pytest.mark.parametrize("min_count", [0, 4])
132131
def test_floating_array_sum(skipna, min_count, dtype):
133132
arr = pd.array([1, 2, 3, None], dtype=dtype)
@@ -171,7 +170,6 @@ def test_preserve_dtypes(op):
171170
tm.assert_frame_equal(result, expected)
172171

173172

174-
@pytest.mark.parametrize("skipna", [True, False])
175173
@pytest.mark.parametrize("method", ["min", "max"])
176174
def test_floating_array_min_max(skipna, method, dtype):
177175
arr = pd.array([0.0, 1.0, None], dtype=dtype)
@@ -183,7 +181,6 @@ def test_floating_array_min_max(skipna, method, dtype):
183181
assert result is pd.NA
184182

185183

186-
@pytest.mark.parametrize("skipna", [True, False])
187184
@pytest.mark.parametrize("min_count", [0, 9])
188185
def test_floating_array_prod(skipna, min_count, dtype):
189186
arr = pd.array([1.0, 2.0, None], dtype=dtype)

pandas/tests/arrays/integer/test_dtypes.py

-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ def test_astype_nansafe():
5959
arr.astype("uint32")
6060

6161

62-
@pytest.mark.parametrize("dropna", [True, False])
6362
def test_construct_index(all_data, dropna):
6463
# ensure that we do not coerce to different Index dtype or non-index
6564

@@ -76,7 +75,6 @@ def test_construct_index(all_data, dropna):
7675
tm.assert_index_equal(result, expected)
7776

7877

79-
@pytest.mark.parametrize("dropna", [True, False])
8078
def test_astype_index(all_data, dropna):
8179
# as an int/uint index to Index
8280

pandas/tests/arrays/integer/test_function.py

-3
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ def test_value_counts_with_normalize():
141141
tm.assert_series_equal(result, expected)
142142

143143

144-
@pytest.mark.parametrize("skipna", [True, False])
145144
@pytest.mark.parametrize("min_count", [0, 4])
146145
def test_integer_array_sum(skipna, min_count, any_int_ea_dtype):
147146
dtype = any_int_ea_dtype
@@ -153,7 +152,6 @@ def test_integer_array_sum(skipna, min_count, any_int_ea_dtype):
153152
assert result is pd.NA
154153

155154

156-
@pytest.mark.parametrize("skipna", [True, False])
157155
@pytest.mark.parametrize("method", ["min", "max"])
158156
def test_integer_array_min_max(skipna, method, any_int_ea_dtype):
159157
dtype = any_int_ea_dtype
@@ -166,7 +164,6 @@ def test_integer_array_min_max(skipna, method, any_int_ea_dtype):
166164
assert result is pd.NA
167165

168166

169-
@pytest.mark.parametrize("skipna", [True, False])
170167
@pytest.mark.parametrize("min_count", [0, 9])
171168
def test_integer_array_prod(skipna, min_count, any_int_ea_dtype):
172169
dtype = any_int_ea_dtype

0 commit comments

Comments
 (0)