Skip to content

TST/CLN: Reuse top level fixtures instead of parametrizations #56583

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 29 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
eed34af
Clean up axis fixtures
mroeschke Dec 20, 2023
ebde8a5
Use top level dropna/observed fixture
mroeschke Dec 20, 2023
ff6c7ef
Use top level sort fixture
mroeschke Dec 20, 2023
3b4f3ec
Use top level sort fixture
mroeschke Dec 20, 2023
dc01991
Use top level skipna fixture
mroeschke Dec 20, 2023
4a3cb13
Use top level keep fixture
mroeschke Dec 20, 2023
c9e3a57
Use top level closed fixture
mroeschke Dec 20, 2023
84ef346
Use top level writable fixture
mroeschke Dec 20, 2023
39ab4b4
Use top level other_closed
mroeschke Dec 20, 2023
0c4829b
Use top level join_type fixture
mroeschke Dec 20, 2023
45c02af
use another join_type
mroeschke Dec 20, 2023
4dd414b
Use another join_type
mroeschke Dec 20, 2023
f37f7b2
use top level nselect_method
mroeschke Dec 20, 2023
c78ede6
Reuse all_boolean_reductions
mroeschke Dec 20, 2023
33a2697
reuse all_numeric_accumulations
mroeschke Dec 20, 2023
1dd3383
Use shared na_action fixture
mroeschke Dec 20, 2023
6c92811
Use top level ascending fixture
mroeschke Dec 20, 2023
3124ac5
Use shared rank_method fixture
mroeschke Dec 20, 2023
db80a7d
Use shared as_index fixture
mroeschke Dec 20, 2023
839f5ad
Share more fixtures
mroeschke Dec 20, 2023
fa876fb
Reuse orient fixture
mroeschke Dec 20, 2023
c31b95f
Use shared cache fixture
mroeschke Dec 20, 2023
07a9a29
Move nogil, parallel, nopython to top level
mroeschke Dec 20, 2023
e5859c8
Use top level center
mroeschke Dec 20, 2023
2fb8365
Reuse more fixtures
mroeschke Dec 20, 2023
d4aba15
Merge remote-tracking branch 'upstream/main' into cln/fixtures
mroeschke Dec 21, 2023
9289d87
Fix errors
mroeschke Dec 21, 2023
f8d8748
Merge remote-tracking branch 'upstream/main' into cln/fixtures
mroeschke Dec 22, 2023
f998704
Merge remote-tracking branch 'upstream/main' into cln/fixtures
mroeschke Dec 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 84 additions & 23 deletions pandas/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,17 +281,6 @@ def axis(request):
return request.param


axis_frame = axis


@pytest.fixture(params=[1, "columns"], ids=lambda x: f"axis={repr(x)}")
def axis_1(request):
"""
Fixture for returning aliases of axis 1 of a DataFrame.
"""
return request.param


@pytest.fixture(params=[True, False, None])
def observed(request):
"""
Expand All @@ -313,6 +302,22 @@ def ordered(request):
return request.param


@pytest.fixture(params=[True, False])
def dropna(request):
"""
Boolean 'dropna' parameter.
"""
return request.param


@pytest.fixture(params=[True, False])
def sort(request):
"""
Boolean 'sort' parameter.
"""
return request.param


@pytest.fixture(params=[True, False])
def skipna(request):
"""
Expand Down Expand Up @@ -414,6 +419,74 @@ def nselect_method(request):
return request.param


@pytest.fixture(params=[None, "ignore"])
def na_action(request):
"""
Fixture for 'na_action' argument in map.
"""
return request.param


@pytest.fixture(params=[True, False])
def ascending(request):
"""
Fixture for 'na_action' argument in sort_values/sort_index/rank.
"""
return request.param


@pytest.fixture(params=["average", "min", "max", "first", "dense"])
def rank_method(request):
"""
Fixture for 'rank' argument in rank.
"""
return request.param


@pytest.fixture(params=[True, False])
def as_index(request):
"""
Fixture for 'as_index' argument in groupby.
"""
return request.param


@pytest.fixture(params=[True, False])
def cache(request):
"""
Fixture for 'cache' argument in to_datetime.
"""
return request.param


@pytest.fixture(params=[True, False])
def parallel(request):
"""
Fixture for parallel keyword argument for numba.jit.
"""
return request.param


# Can parameterize nogil & nopython over True | False, but limiting per
# https://github.com/pandas-dev/pandas/pull/41971#issuecomment-860607472


@pytest.fixture(params=[False])
def nogil(request):
"""
Fixture for nogil keyword argument for numba.jit.
"""
return request.param


@pytest.fixture(params=[True])
def nopython(request):
"""
Fixture for nopython keyword argument for numba.jit.
"""
return request.param


# ----------------------------------------------------------------
# Missing values & co.
# ----------------------------------------------------------------
Expand Down Expand Up @@ -478,10 +551,6 @@ def index_or_series(request):
return request.param


# Generate cartesian product of index_or_series fixture:
index_or_series2 = index_or_series


@pytest.fixture(params=[Index, Series, pd.array], ids=["index", "series", "array"])
def index_or_series_or_array(request):
"""
Expand Down Expand Up @@ -674,10 +743,6 @@ def index(request):
return indices_dict[request.param].copy()


# Needed to generate cartesian product of indices
index_fixture2 = index


@pytest.fixture(
params=[
key for key, value in indices_dict.items() if not isinstance(value, MultiIndex)
Expand All @@ -691,10 +756,6 @@ def index_flat(request):
return indices_dict[key].copy()


# Alias so we can test with cartesian product of index_flat
index_flat2 = index_flat


@pytest.fixture(
params=[
key
Expand Down
7 changes: 3 additions & 4 deletions pandas/tests/apply/test_str.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,9 @@ def test_apply_with_string_funcs(request, float_frame, func, args, kwds, how):
tm.assert_series_equal(result, expected)


@pytest.mark.parametrize("arg", ["sum", "mean", "min", "max", "std"])
def test_with_string_args(datetime_series, arg):
result = datetime_series.apply(arg)
expected = getattr(datetime_series, arg)()
def test_with_string_args(datetime_series, all_numeric_reductions):
result = datetime_series.apply(all_numeric_reductions)
expected = getattr(datetime_series, all_numeric_reductions)()
assert result == expected


Expand Down
4 changes: 0 additions & 4 deletions pandas/tests/arithmetic/test_datetime64.py
Original file line number Diff line number Diff line change
Expand Up @@ -1221,7 +1221,6 @@ class TestDatetime64DateOffsetArithmetic:
# Tick DateOffsets

# TODO: parametrize over timezone?
@pytest.mark.parametrize("unit", ["s", "ms", "us", "ns"])
def test_dt64arr_series_add_tick_DateOffset(self, box_with_array, unit):
# GH#4532
# operate with pd.offsets
Expand Down Expand Up @@ -1311,7 +1310,6 @@ def test_dti_add_tick_tzaware(self, tz_aware_fixture, box_with_array):
# -------------------------------------------------------------
# RelativeDelta DateOffsets

@pytest.mark.parametrize("unit", ["s", "ms", "us", "ns"])
def test_dt64arr_add_sub_relativedelta_offsets(self, box_with_array, unit):
# GH#10699
vec = DatetimeIndex(
Expand Down Expand Up @@ -1422,7 +1420,6 @@ def test_dt64arr_add_sub_relativedelta_offsets(self, box_with_array, unit):
)
@pytest.mark.parametrize("normalize", [True, False])
@pytest.mark.parametrize("n", [0, 5])
@pytest.mark.parametrize("unit", ["s", "ms", "us", "ns"])
@pytest.mark.parametrize("tz", [None, "US/Central"])
def test_dt64arr_add_sub_DateOffsets(
self, box_with_array, n, normalize, cls_and_kwargs, unit, tz
Expand Down Expand Up @@ -2356,7 +2353,6 @@ def test_dti_addsub_object_arraylike(

@pytest.mark.parametrize("years", [-1, 0, 1])
@pytest.mark.parametrize("months", [-2, 0, 2])
@pytest.mark.parametrize("unit", ["s", "ms", "us", "ns"])
def test_shift_months(years, months, unit):
dti = DatetimeIndex(
[
Expand Down
1 change: 0 additions & 1 deletion pandas/tests/arrays/boolean/test_reduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ def test_any_all(values, exp_any, exp_all, exp_any_noskip, exp_all_noskip):
assert np.all(a.all()) is exp_all


@pytest.mark.parametrize("dropna", [True, False])
def test_reductions_return_types(dropna, data, all_numeric_reductions):
op = all_numeric_reductions
s = pd.Series(data)
Expand Down
1 change: 0 additions & 1 deletion pandas/tests/arrays/categorical/test_algos.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import pandas._testing as tm


@pytest.mark.parametrize("ordered", [True, False])
@pytest.mark.parametrize("categories", [["b", "a", "c"], ["a", "b", "c", "d"]])
def test_factorize(categories, ordered):
cat = pd.Categorical(
Expand Down
2 changes: 0 additions & 2 deletions pandas/tests/arrays/categorical/test_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ def test_min_max_ordered_empty(self, categories, expected, aggregation):
"values, categories",
[(["a", "b", "c", np.nan], list("cba")), ([1, 2, 3, np.nan], [3, 2, 1])],
)
@pytest.mark.parametrize("skipna", [True, False])
@pytest.mark.parametrize("function", ["min", "max"])
def test_min_max_with_nan(self, values, categories, function, skipna):
# GH 25303
Expand All @@ -111,7 +110,6 @@ def test_min_max_with_nan(self, values, categories, function, skipna):
assert result == expected

@pytest.mark.parametrize("function", ["min", "max"])
@pytest.mark.parametrize("skipna", [True, False])
def test_min_max_only_nan(self, function, skipna):
# https://github.com/pandas-dev/pandas/issues/33450
cat = Categorical([np.nan], categories=[1, 2], ordered=True)
Expand Down
1 change: 0 additions & 1 deletion pandas/tests/arrays/categorical/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,6 @@ def test_set_categories(self):
(["a", "b", "c"], ["a", "b"], ["d", "e"]),
],
)
@pytest.mark.parametrize("ordered", [True, False])
def test_set_categories_many(self, values, categories, new_categories, ordered):
c = Categorical(values, categories)
expected = Categorical(values, new_categories, ordered)
Expand Down
6 changes: 2 additions & 4 deletions pandas/tests/arrays/categorical/test_astype.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ def test_astype_str_int_categories_to_nullable_float(self):
expected = array(codes, dtype="Float64") / 2
tm.assert_extension_array_equal(res, expected)

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

@pytest.mark.parametrize("dtype_ordered", [True, False])
@pytest.mark.parametrize("cat_ordered", [True, False])
def test_astype_category(self, dtype_ordered, cat_ordered):
def test_astype_category(self, dtype_ordered, ordered):
# GH#10696/GH#18593
data = list("abcaacbab")
cat = Categorical(data, categories=list("bac"), ordered=cat_ordered)
cat = Categorical(data, categories=list("bac"), ordered=ordered)

# standard categories
dtype = CategoricalDtype(ordered=dtype_ordered)
Expand Down
2 changes: 0 additions & 2 deletions pandas/tests/arrays/categorical/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,6 @@ def test_constructor_dtype_and_others_raises(self):
Categorical(["a", "b"], ordered=False, dtype=dtype)

@pytest.mark.parametrize("categories", [None, ["a", "b"], ["a", "c"]])
@pytest.mark.parametrize("ordered", [True, False])
def test_constructor_str_category(self, categories, ordered):
result = Categorical(
["a", "b"], categories=categories, ordered=ordered, dtype="category"
Expand Down Expand Up @@ -683,7 +682,6 @@ def test_from_inferred_categories_coerces(self):
expected = Categorical([1, 1, 2, np.nan])
tm.assert_categorical_equal(result, expected)

@pytest.mark.parametrize("ordered", [None, True, False])
def test_construction_with_ordered(self, ordered):
# GH 9347, 9190
cat = Categorical([0, 1, 2], ordered=ordered)
Expand Down
1 change: 0 additions & 1 deletion pandas/tests/arrays/categorical/test_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ def test_set_dtype_new_categories(self):
(["a", "b", "c"], ["a", "b"], ["d", "e"]),
],
)
@pytest.mark.parametrize("ordered", [True, False])
def test_set_dtype_many(self, values, categories, new_categories, ordered):
c = Categorical(values, categories)
expected = Categorical(values, new_categories, ordered)
Expand Down
5 changes: 0 additions & 5 deletions pandas/tests/arrays/categorical/test_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@
import pandas._testing as tm


@pytest.fixture(params=[None, "ignore"])
def na_action(request):
return request.param


@pytest.mark.parametrize(
"data, categories",
[
Expand Down
1 change: 0 additions & 1 deletion pandas/tests/arrays/datetimes/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ def test_copy(self):
arr = DatetimeArray._from_sequence(data, copy=True)
assert arr._ndarray is not data

@pytest.mark.parametrize("unit", ["s", "ms", "us", "ns"])
def test_numpy_datetime_unit(self, unit):
data = np.array([1, 2, 3], dtype=f"M8[{unit}]")
arr = DatetimeArray._from_sequence(data)
Expand Down
7 changes: 0 additions & 7 deletions pandas/tests/arrays/datetimes/test_reductions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@


class TestReductions:
@pytest.fixture(params=["s", "ms", "us", "ns"])
def unit(self, request):
return request.param

@pytest.fixture
def arr1d(self, tz_naive_fixture):
"""Fixture returning DatetimeArray with parametrized timezones"""
Expand Down Expand Up @@ -54,7 +50,6 @@ def test_min_max(self, arr1d, unit):
assert result is NaT

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

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

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

Expand Down
3 changes: 0 additions & 3 deletions pandas/tests/arrays/floating/test_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ def test_value_counts_with_normalize():
tm.assert_series_equal(result, expected)


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


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


@pytest.mark.parametrize("skipna", [True, False])
@pytest.mark.parametrize("min_count", [0, 9])
def test_floating_array_prod(skipna, min_count, dtype):
arr = pd.array([1.0, 2.0, None], dtype=dtype)
Expand Down
2 changes: 0 additions & 2 deletions pandas/tests/arrays/integer/test_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ def test_astype_nansafe():
arr.astype("uint32")


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

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


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

Expand Down
3 changes: 0 additions & 3 deletions pandas/tests/arrays/integer/test_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ def test_value_counts_with_normalize():
tm.assert_series_equal(result, expected)


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


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


@pytest.mark.parametrize("skipna", [True, False])
@pytest.mark.parametrize("min_count", [0, 9])
def test_integer_array_prod(skipna, min_count, any_int_ea_dtype):
dtype = any_int_ea_dtype
Expand Down
Loading