From eed34af7de4709d66d05a8a9a2e7898600bbdc85 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Wed, 20 Dec 2023 11:38:52 -0800 Subject: [PATCH 01/26] Clean up axis fixtures --- pandas/conftest.py | 19 ------------------ pandas/tests/frame/methods/test_at_time.py | 1 - pandas/tests/groupby/methods/test_size.py | 1 + pandas/tests/indexes/test_setops.py | 5 +++++ pandas/tests/reshape/concat/test_dataframe.py | 1 - pandas/tests/window/test_expanding.py | 6 +++--- pandas/tests/window/test_rolling.py | 20 +++++++++---------- 7 files changed, 19 insertions(+), 34 deletions(-) diff --git a/pandas/conftest.py b/pandas/conftest.py index 983272d79081e..152a5efb92add 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -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): """ @@ -674,10 +663,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) @@ -691,10 +676,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 diff --git a/pandas/tests/frame/methods/test_at_time.py b/pandas/tests/frame/methods/test_at_time.py index 4c1434bd66aff..1ebe9920933d1 100644 --- a/pandas/tests/frame/methods/test_at_time.py +++ b/pandas/tests/frame/methods/test_at_time.py @@ -95,7 +95,6 @@ def test_at_time_raises(self, frame_or_series): with pytest.raises(TypeError, match=msg): # index is not a DatetimeIndex obj.at_time("00:00") - @pytest.mark.parametrize("axis", ["index", "columns", 0, 1]) def test_at_time_axis(self, axis): # issue 8839 rng = date_range("1/1/2000", "1/5/2000", freq="5min") diff --git a/pandas/tests/groupby/methods/test_size.py b/pandas/tests/groupby/methods/test_size.py index 93a4e743d0d71..c4d31eb9ada59 100644 --- a/pandas/tests/groupby/methods/test_size.py +++ b/pandas/tests/groupby/methods/test_size.py @@ -32,6 +32,7 @@ def test_size(df, by): pytest.param([None, None, None, None], marks=pytest.mark.xfail), ], ) +@pytest.mark.parametrize("axis_1", [1, "columns"]) def test_size_axis_1(df, axis_1, by, sort, dropna): # GH#45715 counts = {key: sum(value == key for value in by) for key in dict.fromkeys(by)} diff --git a/pandas/tests/indexes/test_setops.py b/pandas/tests/indexes/test_setops.py index 4a6982cf98670..8f4dd1c64236a 100644 --- a/pandas/tests/indexes/test_setops.py +++ b/pandas/tests/indexes/test_setops.py @@ -56,6 +56,11 @@ def any_dtype_for_small_pos_integer_indexes(request): return request.param +@pytest.fixture +def index_flat2(index_flat): + return index_flat + + def test_union_same_types(index): # Union with a non-unique, non-monotonic index raises error # Only needed for bool index factory diff --git a/pandas/tests/reshape/concat/test_dataframe.py b/pandas/tests/reshape/concat/test_dataframe.py index f288921c25753..8aefa9262dbc5 100644 --- a/pandas/tests/reshape/concat/test_dataframe.py +++ b/pandas/tests/reshape/concat/test_dataframe.py @@ -194,7 +194,6 @@ def test_concat_duplicates_in_index_with_keys(self): @pytest.mark.parametrize("ignore_index", [True, False]) @pytest.mark.parametrize("order", ["C", "F"]) - @pytest.mark.parametrize("axis", [0, 1]) def test_concat_copies(self, axis, order, ignore_index, using_copy_on_write): # based on asv ConcatDataFrames df = DataFrame(np.zeros((10, 5), dtype=np.float32, order=order)) diff --git a/pandas/tests/window/test_expanding.py b/pandas/tests/window/test_expanding.py index aebb9e86c763f..e56d62e98d258 100644 --- a/pandas/tests/window/test_expanding.py +++ b/pandas/tests/window/test_expanding.py @@ -79,10 +79,10 @@ def test_missing_minp_zero(): tm.assert_series_equal(result, expected) -def test_expanding_axis(axis_frame): +def test_expanding_axis(axis): # see gh-23372. df = DataFrame(np.ones((10, 20))) - axis = df._get_axis_number(axis_frame) + axis = df._get_axis_number(axis) if axis == 0: msg = "The 'axis' keyword in DataFrame.expanding is deprecated" @@ -95,7 +95,7 @@ def test_expanding_axis(axis_frame): expected = DataFrame([[np.nan] * 2 + [float(i) for i in range(3, 21)]] * 10) with tm.assert_produces_warning(FutureWarning, match=msg): - result = df.expanding(3, axis=axis_frame).sum() + result = df.expanding(3, axis=axis).sum() tm.assert_frame_equal(result, expected) diff --git a/pandas/tests/window/test_rolling.py b/pandas/tests/window/test_rolling.py index f353a7fa2f0fe..e1362109c8157 100644 --- a/pandas/tests/window/test_rolling.py +++ b/pandas/tests/window/test_rolling.py @@ -594,10 +594,10 @@ def test_multi_index_names(): assert result.index.names == [None, "1", "2"] -def test_rolling_axis_sum(axis_frame): +def test_rolling_axis_sum(axis): # see gh-23372. df = DataFrame(np.ones((10, 20))) - axis = df._get_axis_number(axis_frame) + axis = df._get_axis_number(axis) if axis == 0: msg = "The 'axis' keyword in DataFrame.rolling" @@ -608,15 +608,15 @@ def test_rolling_axis_sum(axis_frame): expected = DataFrame([[np.nan] * 2 + [3.0] * 18] * 10) with tm.assert_produces_warning(FutureWarning, match=msg): - result = df.rolling(3, axis=axis_frame).sum() + result = df.rolling(3, axis=axis).sum() tm.assert_frame_equal(result, expected) -def test_rolling_axis_count(axis_frame): +def test_rolling_axis_count(axis): # see gh-26055 df = DataFrame({"x": range(3), "y": range(3)}) - axis = df._get_axis_number(axis_frame) + axis = df._get_axis_number(axis) if axis in [0, "index"]: msg = "The 'axis' keyword in DataFrame.rolling" @@ -626,7 +626,7 @@ def test_rolling_axis_count(axis_frame): expected = DataFrame({"x": [1.0, 1.0, 1.0], "y": [2.0, 2.0, 2.0]}) with tm.assert_produces_warning(FutureWarning, match=msg): - result = df.rolling(2, axis=axis_frame, min_periods=0).count() + result = df.rolling(2, axis=axis, min_periods=0).count() tm.assert_frame_equal(result, expected) @@ -639,21 +639,21 @@ def test_readonly_array(): tm.assert_series_equal(result, expected) -def test_rolling_datetime(axis_frame, tz_naive_fixture): +def test_rolling_datetime(axis, tz_naive_fixture): # GH-28192 tz = tz_naive_fixture df = DataFrame( {i: [1] * 2 for i in date_range("2019-8-01", "2019-08-03", freq="D", tz=tz)} ) - if axis_frame in [0, "index"]: + if axis in [0, "index"]: msg = "The 'axis' keyword in DataFrame.rolling" with tm.assert_produces_warning(FutureWarning, match=msg): - result = df.T.rolling("2D", axis=axis_frame).sum().T + result = df.T.rolling("2D", axis=axis).sum().T else: msg = "Support for axis=1 in DataFrame.rolling" with tm.assert_produces_warning(FutureWarning, match=msg): - result = df.rolling("2D", axis=axis_frame).sum() + result = df.rolling("2D", axis=axis).sum() expected = DataFrame( { **{ From ebde8a516bd0eb14bb25655dcfebd91030b791c2 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Wed, 20 Dec 2023 11:44:02 -0800 Subject: [PATCH 02/26] Use top level dropna/observed fixture --- pandas/conftest.py | 8 ++++++++ pandas/tests/groupby/conftest.py | 10 ---------- pandas/tests/reshape/test_pivot.py | 5 ----- 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/pandas/conftest.py b/pandas/conftest.py index 152a5efb92add..ac95557378dce 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -302,6 +302,14 @@ 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 skipna(request): """ diff --git a/pandas/tests/groupby/conftest.py b/pandas/tests/groupby/conftest.py index dce3f072ed903..e93b7472cc286 100644 --- a/pandas/tests/groupby/conftest.py +++ b/pandas/tests/groupby/conftest.py @@ -23,16 +23,6 @@ def as_index(request): return request.param -@pytest.fixture(params=[True, False]) -def dropna(request): - return request.param - - -@pytest.fixture(params=[True, False]) -def observed(request): - return request.param - - @pytest.fixture def df(): return DataFrame( diff --git a/pandas/tests/reshape/test_pivot.py b/pandas/tests/reshape/test_pivot.py index 18a449b4d0c67..5ca0da3991b8e 100644 --- a/pandas/tests/reshape/test_pivot.py +++ b/pandas/tests/reshape/test_pivot.py @@ -30,11 +30,6 @@ from pandas.core.reshape.pivot import pivot_table -@pytest.fixture(params=[True, False]) -def dropna(request): - return request.param - - @pytest.fixture(params=[([0] * 4, [1] * 4), (range(3), range(1, 4))]) def interval_values(request, closed): left, right = request.param From ff6c7ef7cb6e2d1361943b22137cc55a87f80014 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Wed, 20 Dec 2023 11:46:31 -0800 Subject: [PATCH 03/26] Use top level sort fixture --- pandas/conftest.py | 8 ++++++++ pandas/tests/groupby/conftest.py | 5 ----- pandas/tests/indexes/conftest.py | 3 +-- pandas/tests/reshape/concat/conftest.py | 7 ------- 4 files changed, 9 insertions(+), 14 deletions(-) delete mode 100644 pandas/tests/reshape/concat/conftest.py diff --git a/pandas/conftest.py b/pandas/conftest.py index ac95557378dce..51bf494361862 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -310,6 +310,14 @@ def dropna(request): 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): """ diff --git a/pandas/tests/groupby/conftest.py b/pandas/tests/groupby/conftest.py index e93b7472cc286..187076a7bac0d 100644 --- a/pandas/tests/groupby/conftest.py +++ b/pandas/tests/groupby/conftest.py @@ -13,11 +13,6 @@ ) -@pytest.fixture(params=[True, False]) -def sort(request): - return request.param - - @pytest.fixture(params=[True, False]) def as_index(request): return request.param diff --git a/pandas/tests/indexes/conftest.py b/pandas/tests/indexes/conftest.py index bfb7acdcf4812..61f6be000cee8 100644 --- a/pandas/tests/indexes/conftest.py +++ b/pandas/tests/indexes/conftest.py @@ -15,8 +15,7 @@ def sort(request): Caution: Don't confuse this one with the "sort" fixture used - for DataFrame.append or concat. That one has - parameters [True, False]. + for concat. That one has parameters [True, False]. We can't combine them as sort=True is not permitted in the Index setops methods. diff --git a/pandas/tests/reshape/concat/conftest.py b/pandas/tests/reshape/concat/conftest.py deleted file mode 100644 index 62b8c59ba8855..0000000000000 --- a/pandas/tests/reshape/concat/conftest.py +++ /dev/null @@ -1,7 +0,0 @@ -import pytest - - -@pytest.fixture(params=[True, False]) -def sort(request): - """Boolean sort keyword for concat and DataFrame.append.""" - return request.param From 3b4f3ecaa4e8b9390dbdd3e2c9747098de3da9d4 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Wed, 20 Dec 2023 11:49:52 -0800 Subject: [PATCH 04/26] Use top level sort fixture --- pandas/tests/frame/methods/test_join.py | 4 ++-- pandas/tests/frame/test_stack_unstack.py | 1 - pandas/tests/groupby/methods/test_size.py | 1 - pandas/tests/groupby/methods/test_value_counts.py | 2 -- pandas/tests/groupby/test_categorical.py | 1 - pandas/tests/groupby/test_grouping.py | 2 -- pandas/tests/groupby/test_reductions.py | 3 --- pandas/tests/reshape/merge/test_merge.py | 1 - pandas/tests/reshape/merge/test_multi.py | 2 -- pandas/tests/test_algos.py | 4 ---- pandas/tests/test_sorting.py | 1 - 11 files changed, 2 insertions(+), 20 deletions(-) diff --git a/pandas/tests/frame/methods/test_join.py b/pandas/tests/frame/methods/test_join.py index 735f6c50ab739..02f0b9e20871d 100644 --- a/pandas/tests/frame/methods/test_join.py +++ b/pandas/tests/frame/methods/test_join.py @@ -391,8 +391,8 @@ def test_join_list_series(float_frame): tm.assert_frame_equal(result, float_frame) -@pytest.mark.parametrize("sort_kw", [True, False]) -def test_suppress_future_warning_with_sort_kw(sort_kw): +def test_suppress_future_warning_with_sort_kw(sort): + sort_kw = sort a = DataFrame({"col1": [1, 2]}, index=["c", "a"]) b = DataFrame({"col2": [4, 5]}, index=["b", "a"]) diff --git a/pandas/tests/frame/test_stack_unstack.py b/pandas/tests/frame/test_stack_unstack.py index 554a9d4ce2d5d..06cc440840e51 100644 --- a/pandas/tests/frame/test_stack_unstack.py +++ b/pandas/tests/frame/test_stack_unstack.py @@ -2207,7 +2207,6 @@ def __init__(self, *args, **kwargs) -> None: ), ) @pytest.mark.parametrize("stack_lev", range(2)) - @pytest.mark.parametrize("sort", [True, False]) def test_stack_order_with_unsorted_levels( self, levels, stack_lev, sort, future_stack ): diff --git a/pandas/tests/groupby/methods/test_size.py b/pandas/tests/groupby/methods/test_size.py index c4d31eb9ada59..92a277d8014d4 100644 --- a/pandas/tests/groupby/methods/test_size.py +++ b/pandas/tests/groupby/methods/test_size.py @@ -52,7 +52,6 @@ def test_size_axis_1(df, axis_1, by, sort, dropna): @pytest.mark.parametrize("by", ["A", "B", ["A", "B"]]) -@pytest.mark.parametrize("sort", [True, False]) def test_size_sort(sort, by): df = DataFrame(np.random.default_rng(2).choice(20, (1000, 3)), columns=list("ABC")) left = df.groupby(by=by, sort=sort).size() diff --git a/pandas/tests/groupby/methods/test_value_counts.py b/pandas/tests/groupby/methods/test_value_counts.py index 2fa79c815d282..538ed7f93f857 100644 --- a/pandas/tests/groupby/methods/test_value_counts.py +++ b/pandas/tests/groupby/methods/test_value_counts.py @@ -76,9 +76,7 @@ def seed_df(seed_nans, n, m): @pytest.mark.parametrize("bins", [None, [0, 5]], ids=repr) @pytest.mark.parametrize("isort", [True, False]) @pytest.mark.parametrize("normalize, name", [(True, "proportion"), (False, "count")]) -@pytest.mark.parametrize("sort", [True, False]) @pytest.mark.parametrize("ascending", [True, False]) -@pytest.mark.parametrize("dropna", [True, False]) def test_series_groupby_value_counts( seed_nans, num_rows, diff --git a/pandas/tests/groupby/test_categorical.py b/pandas/tests/groupby/test_categorical.py index 7a91601bf688f..a2cc7fd782396 100644 --- a/pandas/tests/groupby/test_categorical.py +++ b/pandas/tests/groupby/test_categorical.py @@ -618,7 +618,6 @@ def test_dataframe_categorical_with_nan(observed): @pytest.mark.parametrize("ordered", [True, False]) @pytest.mark.parametrize("observed", [True, False]) -@pytest.mark.parametrize("sort", [True, False]) def test_dataframe_categorical_ordered_observed_sort(ordered, observed, sort): # GH 25871: Fix groupby sorting on ordered Categoricals # GH 25167: Groupby with observed=True doesn't sort diff --git a/pandas/tests/groupby/test_grouping.py b/pandas/tests/groupby/test_grouping.py index 363ff883385db..782bb7eb7984e 100644 --- a/pandas/tests/groupby/test_grouping.py +++ b/pandas/tests/groupby/test_grouping.py @@ -649,7 +649,6 @@ def test_groupby_multiindex_partial_indexing_equivalence(self): result_groups = df.groupby([("a", 1)])["b"].groups tm.assert_dict_equal(expected_groups, result_groups) - @pytest.mark.parametrize("sort", [True, False]) def test_groupby_level(self, sort, multiindex_dataframe_random_data, df): # GH 17537 frame = multiindex_dataframe_random_data @@ -708,7 +707,6 @@ def test_groupby_level_index_names(self, axis): with tm.assert_produces_warning(FutureWarning, match=depr_msg): df.groupby(level="foo", axis=axis) - @pytest.mark.parametrize("sort", [True, False]) def test_groupby_level_with_nas(self, sort): # GH 17537 index = MultiIndex( diff --git a/pandas/tests/groupby/test_reductions.py b/pandas/tests/groupby/test_reductions.py index 425079f943aba..18d59cd3cd593 100644 --- a/pandas/tests/groupby/test_reductions.py +++ b/pandas/tests/groupby/test_reductions.py @@ -639,8 +639,6 @@ def test_max_nan_bug(): @pytest.mark.slow -@pytest.mark.parametrize("sort", [False, True]) -@pytest.mark.parametrize("dropna", [False, True]) @pytest.mark.parametrize("as_index", [True, False]) @pytest.mark.parametrize("with_nan", [True, False]) @pytest.mark.parametrize("keys", [["joe"], ["joe", "jim"]]) @@ -1026,7 +1024,6 @@ def test_apply_to_nullable_integer_returns_float(values, function): ) @pytest.mark.parametrize("axis", [0, 1]) @pytest.mark.parametrize("skipna", [True, False]) -@pytest.mark.parametrize("sort", [True, False]) def test_regression_allowlist_methods(op, axis, skipna, sort): # GH6944 # GH 17537 diff --git a/pandas/tests/reshape/merge/test_merge.py b/pandas/tests/reshape/merge/test_merge.py index d7a343ae9f152..3c0965308f8b7 100644 --- a/pandas/tests/reshape/merge/test_merge.py +++ b/pandas/tests/reshape/merge/test_merge.py @@ -2860,7 +2860,6 @@ def test_merge_multiindex_single_level(): @pytest.mark.parametrize("how", ["left", "right", "inner", "outer"]) -@pytest.mark.parametrize("sort", [True, False]) @pytest.mark.parametrize("on_index", [True, False]) @pytest.mark.parametrize("left_unique", [True, False]) @pytest.mark.parametrize("left_monotonic", [True, False]) diff --git a/pandas/tests/reshape/merge/test_multi.py b/pandas/tests/reshape/merge/test_multi.py index 269d3a2b7078e..bc02da0d5b97b 100644 --- a/pandas/tests/reshape/merge/test_multi.py +++ b/pandas/tests/reshape/merge/test_multi.py @@ -88,7 +88,6 @@ def test_merge_on_multikey(self, left, right, join_type): tm.assert_frame_equal(result, expected) - @pytest.mark.parametrize("sort", [False, True]) def test_left_join_multi_index(self, sort): icols = ["1st", "2nd", "3rd"] @@ -150,7 +149,6 @@ def run_asserts(left, right, sort): run_asserts(left, right, sort) - @pytest.mark.parametrize("sort", [False, True]) def test_merge_right_vs_left(self, left, right, sort): # compare left vs right merge with multikey on_cols = ["key1", "key2"] diff --git a/pandas/tests/test_algos.py b/pandas/tests/test_algos.py index 718d1b3ee2e83..16d684b72e1e3 100644 --- a/pandas/tests/test_algos.py +++ b/pandas/tests/test_algos.py @@ -63,7 +63,6 @@ def test_factorize_complex(self): expected_uniques = np.array([(1 + 0j), (2 + 0j), (2 + 1j)], dtype=object) tm.assert_numpy_array_equal(uniques, expected_uniques) - @pytest.mark.parametrize("sort", [True, False]) def test_factorize(self, index_or_series_obj, sort): obj = index_or_series_obj result_codes, result_uniques = obj.factorize(sort=sort) @@ -354,7 +353,6 @@ def test_datetime64_factorize(self, writable): tm.assert_numpy_array_equal(codes, expected_codes) tm.assert_numpy_array_equal(uniques, expected_uniques) - @pytest.mark.parametrize("sort", [True, False]) def test_factorize_rangeindex(self, sort): # increasing -> sort doesn't matter ri = pd.RangeIndex.from_range(range(10)) @@ -368,7 +366,6 @@ def test_factorize_rangeindex(self, sort): tm.assert_numpy_array_equal(result[0], expected[0]) tm.assert_index_equal(result[1], expected[1], exact=True) - @pytest.mark.parametrize("sort", [True, False]) def test_factorize_rangeindex_decreasing(self, sort): # decreasing -> sort matters ri = pd.RangeIndex.from_range(range(10)) @@ -431,7 +428,6 @@ def test_parametrized_factorize_na_value(self, data, na_value): tm.assert_numpy_array_equal(codes, expected_codes) tm.assert_numpy_array_equal(uniques, expected_uniques) - @pytest.mark.parametrize("sort", [True, False]) @pytest.mark.parametrize( "data, uniques", [ diff --git a/pandas/tests/test_sorting.py b/pandas/tests/test_sorting.py index 285f240028152..e692d8326c5ba 100644 --- a/pandas/tests/test_sorting.py +++ b/pandas/tests/test_sorting.py @@ -240,7 +240,6 @@ def test_int64_overflow_sort_false_order(self, left_right): @pytest.mark.slow @pytest.mark.parametrize("how", ["left", "right", "outer", "inner"]) - @pytest.mark.parametrize("sort", [True, False]) def test_int64_overflow_one_to_many_none_match(self, how, sort): # one-2-many/none match low, high, n = -1 << 10, 1 << 10, 1 << 11 From dc01991a6ac728ae69e4e93639acd5ca93b13fa9 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Wed, 20 Dec 2023 11:55:06 -0800 Subject: [PATCH 05/26] Use top level skipna fixture --- pandas/tests/arrays/categorical/test_analytics.py | 2 -- pandas/tests/arrays/datetimes/test_reductions.py | 3 --- pandas/tests/arrays/floating/test_function.py | 3 --- pandas/tests/arrays/integer/test_function.py | 3 --- pandas/tests/arrays/period/test_reductions.py | 3 --- pandas/tests/arrays/string_/test_string.py | 3 --- pandas/tests/arrays/timedeltas/test_reductions.py | 2 -- pandas/tests/dtypes/test_inference.py | 6 ------ pandas/tests/extension/base/accumulate.py | 1 - pandas/tests/extension/base/dtype.py | 1 - pandas/tests/extension/base/reduce.py | 3 --- pandas/tests/extension/test_arrow.py | 5 ----- pandas/tests/extension/test_datetime.py | 1 - pandas/tests/extension/test_numpy.py | 1 - pandas/tests/extension/test_sparse.py | 2 -- pandas/tests/frame/test_reductions.py | 3 --- pandas/tests/groupby/test_reductions.py | 1 - pandas/tests/reductions/test_reductions.py | 5 ----- pandas/tests/series/test_reductions.py | 1 - 19 files changed, 49 deletions(-) diff --git a/pandas/tests/arrays/categorical/test_analytics.py b/pandas/tests/arrays/categorical/test_analytics.py index c2c53fbc4637e..1021b18f4ae71 100644 --- a/pandas/tests/arrays/categorical/test_analytics.py +++ b/pandas/tests/arrays/categorical/test_analytics.py @@ -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 @@ -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) diff --git a/pandas/tests/arrays/datetimes/test_reductions.py b/pandas/tests/arrays/datetimes/test_reductions.py index a941546b13a56..7d83fe6ffac7d 100644 --- a/pandas/tests/arrays/datetimes/test_reductions.py +++ b/pandas/tests/arrays/datetimes/test_reductions.py @@ -54,7 +54,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) @@ -65,7 +64,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) @@ -164,7 +162,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] diff --git a/pandas/tests/arrays/floating/test_function.py b/pandas/tests/arrays/floating/test_function.py index 40fd66fd049a6..9ea48bfb2413f 100644 --- a/pandas/tests/arrays/floating/test_function.py +++ b/pandas/tests/arrays/floating/test_function.py @@ -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) @@ -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) @@ -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) diff --git a/pandas/tests/arrays/integer/test_function.py b/pandas/tests/arrays/integer/test_function.py index d48b636a98feb..33300fff925f6 100644 --- a/pandas/tests/arrays/integer/test_function.py +++ b/pandas/tests/arrays/integer/test_function.py @@ -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 @@ -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 @@ -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 diff --git a/pandas/tests/arrays/period/test_reductions.py b/pandas/tests/arrays/period/test_reductions.py index 2889cc786dd71..5b859d86eb6d0 100644 --- a/pandas/tests/arrays/period/test_reductions.py +++ b/pandas/tests/arrays/period/test_reductions.py @@ -1,5 +1,3 @@ -import pytest - import pandas as pd from pandas.core.arrays import period_array @@ -32,7 +30,6 @@ def test_min_max(self): result = arr.max(skipna=False) assert result is pd.NaT - @pytest.mark.parametrize("skipna", [True, False]) def test_min_max_empty(self, skipna): arr = period_array([], freq="D") result = arr.min(skipna=skipna) diff --git a/pandas/tests/arrays/string_/test_string.py b/pandas/tests/arrays/string_/test_string.py index 41255b2516e7e..66bd0f3f40083 100644 --- a/pandas/tests/arrays/string_/test_string.py +++ b/pandas/tests/arrays/string_/test_string.py @@ -415,7 +415,6 @@ def test_astype_float(dtype, any_float_dtype): tm.assert_series_equal(result, expected) -@pytest.mark.parametrize("skipna", [True, False]) @pytest.mark.xfail(reason="Not implemented StringArray.sum") def test_reduce(skipna, dtype): arr = pd.Series(["a", "b", "c"], dtype=dtype) @@ -423,7 +422,6 @@ def test_reduce(skipna, dtype): assert result == "abc" -@pytest.mark.parametrize("skipna", [True, False]) @pytest.mark.xfail(reason="Not implemented StringArray.sum") def test_reduce_missing(skipna, dtype): arr = pd.Series([None, "a", None, "b", "c", None], dtype=dtype) @@ -435,7 +433,6 @@ def test_reduce_missing(skipna, dtype): @pytest.mark.parametrize("method", ["min", "max"]) -@pytest.mark.parametrize("skipna", [True, False]) def test_min_max(method, skipna, dtype): arr = pd.Series(["a", "b", "c", None], dtype=dtype) result = getattr(arr, method)(skipna=skipna) diff --git a/pandas/tests/arrays/timedeltas/test_reductions.py b/pandas/tests/arrays/timedeltas/test_reductions.py index f1d2cc6a90519..d9d81e886efc4 100644 --- a/pandas/tests/arrays/timedeltas/test_reductions.py +++ b/pandas/tests/arrays/timedeltas/test_reductions.py @@ -10,7 +10,6 @@ class TestReductions: @pytest.mark.parametrize("name", ["std", "min", "max", "median", "mean"]) - @pytest.mark.parametrize("skipna", [True, False]) def test_reductions_empty(self, name, skipna): tdi = pd.TimedeltaIndex([]) arr = tdi.array @@ -21,7 +20,6 @@ def test_reductions_empty(self, name, skipna): result = getattr(arr, name)(skipna=skipna) assert result is pd.NaT - @pytest.mark.parametrize("skipna", [True, False]) def test_sum_empty(self, skipna): tdi = pd.TimedeltaIndex([]) arr = tdi.array diff --git a/pandas/tests/dtypes/test_inference.py b/pandas/tests/dtypes/test_inference.py index ff2cfc1278331..82db41de27117 100644 --- a/pandas/tests/dtypes/test_inference.py +++ b/pandas/tests/dtypes/test_inference.py @@ -1050,7 +1050,6 @@ def test_inferred_dtype_fixture(self, any_skipna_inferred_dtype): # make sure the inferred dtype of the fixture is as requested assert inferred_dtype == lib.infer_dtype(values, skipna=True) - @pytest.mark.parametrize("skipna", [True, False]) def test_length_zero(self, skipna): result = lib.infer_dtype(np.array([], dtype="i4"), skipna=skipna) assert result == "integer" @@ -1162,7 +1161,6 @@ def test_decimals(self): assert result == "decimal" # complex is compatible with nan, so skipna has no effect - @pytest.mark.parametrize("skipna", [True, False]) def test_complex(self, skipna): # gets cast to complex on array construction arr = np.array([1.0, 2.0, 1 + 1j]) @@ -1342,7 +1340,6 @@ def test_infer_dtype_period(self): assert lib.infer_dtype(arr, skipna=True) == "mixed" @pytest.mark.parametrize("klass", [pd.array, Series, Index]) - @pytest.mark.parametrize("skipna", [True, False]) def test_infer_dtype_period_array(self, klass, skipna): # https://github.com/pandas-dev/pandas/issues/23553 values = klass( @@ -1532,7 +1529,6 @@ def test_date(self): [pd.NaT, date(2020, 1, 1)], ], ) - @pytest.mark.parametrize("skipna", [True, False]) def test_infer_dtype_date_order_invariant(self, values, skipna): # https://github.com/pandas-dev/pandas/issues/33741 result = lib.infer_dtype(values, skipna=skipna) @@ -1704,7 +1700,6 @@ def test_interval_mismatched_subtype(self): assert lib.infer_dtype(arr, skipna=False) == "interval" @pytest.mark.parametrize("klass", [pd.array, Series]) - @pytest.mark.parametrize("skipna", [True, False]) @pytest.mark.parametrize("data", [["a", "b", "c"], ["a", "b", pd.NA]]) def test_string_dtype(self, data, skipna, klass, nullable_string_dtype): # StringArray @@ -1713,7 +1708,6 @@ def test_string_dtype(self, data, skipna, klass, nullable_string_dtype): assert inferred == "string" @pytest.mark.parametrize("klass", [pd.array, Series]) - @pytest.mark.parametrize("skipna", [True, False]) @pytest.mark.parametrize("data", [[True, False, True], [True, False, pd.NA]]) def test_boolean_dtype(self, data, skipna, klass): # BooleanArray diff --git a/pandas/tests/extension/base/accumulate.py b/pandas/tests/extension/base/accumulate.py index 9a41a3a582c4a..9189ef7ec9aa5 100644 --- a/pandas/tests/extension/base/accumulate.py +++ b/pandas/tests/extension/base/accumulate.py @@ -26,7 +26,6 @@ def check_accumulate(self, ser: pd.Series, op_name: str, skipna: bool): expected = getattr(alt, op_name)(skipna=skipna) tm.assert_series_equal(result, expected, check_dtype=False) - @pytest.mark.parametrize("skipna", [True, False]) def test_accumulate_series(self, data, all_numeric_accumulations, skipna): op_name = all_numeric_accumulations ser = pd.Series(data) diff --git a/pandas/tests/extension/base/dtype.py b/pandas/tests/extension/base/dtype.py index c7b768f6e3c88..3fb116430861a 100644 --- a/pandas/tests/extension/base/dtype.py +++ b/pandas/tests/extension/base/dtype.py @@ -114,7 +114,6 @@ def test_get_common_dtype(self, dtype): # only case we can test in general) assert dtype._get_common_dtype([dtype]) == dtype - @pytest.mark.parametrize("skipna", [True, False]) def test_infer_dtype(self, data, data_missing, skipna): # only testing that this works without raising an error res = infer_dtype(data, skipna=skipna) diff --git a/pandas/tests/extension/base/reduce.py b/pandas/tests/extension/base/reduce.py index 6ea1b3a6fbe9d..2a443901fa41a 100644 --- a/pandas/tests/extension/base/reduce.py +++ b/pandas/tests/extension/base/reduce.py @@ -77,7 +77,6 @@ def check_reduce_frame(self, ser: pd.Series, op_name: str, skipna: bool): tm.assert_extension_array_equal(result1, expected) - @pytest.mark.parametrize("skipna", [True, False]) def test_reduce_series_boolean(self, data, all_boolean_reductions, skipna): op_name = all_boolean_reductions ser = pd.Series(data) @@ -96,7 +95,6 @@ def test_reduce_series_boolean(self, data, all_boolean_reductions, skipna): self.check_reduce(ser, op_name, skipna) @pytest.mark.filterwarnings("ignore::RuntimeWarning") - @pytest.mark.parametrize("skipna", [True, False]) def test_reduce_series_numeric(self, data, all_numeric_reductions, skipna): op_name = all_numeric_reductions ser = pd.Series(data) @@ -115,7 +113,6 @@ def test_reduce_series_numeric(self, data, all_numeric_reductions, skipna): # min/max with empty produce numpy warnings self.check_reduce(ser, op_name, skipna) - @pytest.mark.parametrize("skipna", [True, False]) def test_reduce_frame(self, data, all_numeric_reductions, skipna): op_name = all_numeric_reductions ser = pd.Series(data) diff --git a/pandas/tests/extension/test_arrow.py b/pandas/tests/extension/test_arrow.py index 674a5da216011..d4a4bc8bb8bd3 100644 --- a/pandas/tests/extension/test_arrow.py +++ b/pandas/tests/extension/test_arrow.py @@ -418,7 +418,6 @@ def _supports_accumulation(self, ser: pd.Series, op_name: str) -> bool: return False return True - @pytest.mark.parametrize("skipna", [True, False]) def test_accumulate_series(self, data, all_numeric_accumulations, skipna, request): pa_type = data.dtype.pyarrow_dtype op_name = all_numeric_accumulations @@ -520,7 +519,6 @@ def check_reduce(self, ser: pd.Series, op_name: str, skipna: bool): expected = getattr(alt, op_name)(skipna=skipna) tm.assert_almost_equal(result, expected) - @pytest.mark.parametrize("skipna", [True, False]) def test_reduce_series_numeric(self, data, all_numeric_reductions, skipna, request): dtype = data.dtype pa_dtype = dtype.pyarrow_dtype @@ -546,7 +544,6 @@ def test_reduce_series_numeric(self, data, all_numeric_reductions, skipna, reque request.applymarker(xfail_mark) super().test_reduce_series_numeric(data, all_numeric_reductions, skipna) - @pytest.mark.parametrize("skipna", [True, False]) def test_reduce_series_boolean( self, data, all_boolean_reductions, skipna, na_value, request ): @@ -583,7 +580,6 @@ def _get_expected_reduction_dtype(self, arr, op_name: str, skipna: bool): }[arr.dtype.kind] return cmp_dtype - @pytest.mark.parametrize("skipna", [True, False]) def test_reduce_frame(self, data, all_numeric_reductions, skipna, request): op_name = all_numeric_reductions if op_name == "skew": @@ -2703,7 +2699,6 @@ def test_dt_tz_convert(unit): tm.assert_series_equal(result, expected) -@pytest.mark.parametrize("skipna", [True, False]) def test_boolean_reduce_series_all_null(all_boolean_reductions, skipna): # GH51624 ser = pd.Series([None], dtype="float64[pyarrow]") diff --git a/pandas/tests/extension/test_datetime.py b/pandas/tests/extension/test_datetime.py index efb88dc7bd4e1..a60ece09dc73e 100644 --- a/pandas/tests/extension/test_datetime.py +++ b/pandas/tests/extension/test_datetime.py @@ -94,7 +94,6 @@ def _supports_accumulation(self, ser, op_name: str) -> bool: def _supports_reduction(self, obj, op_name: str) -> bool: return op_name in ["min", "max", "median", "mean", "std", "any", "all"] - @pytest.mark.parametrize("skipna", [True, False]) def test_reduce_series_boolean(self, data, all_boolean_reductions, skipna): meth = all_boolean_reductions msg = f"'{meth}' with datetime64 dtypes is deprecated and will raise in" diff --git a/pandas/tests/extension/test_numpy.py b/pandas/tests/extension/test_numpy.py index aaf49f53ba02b..8bf16272dd8c5 100644 --- a/pandas/tests/extension/test_numpy.py +++ b/pandas/tests/extension/test_numpy.py @@ -313,7 +313,6 @@ def check_reduce(self, ser: pd.Series, op_name: str, skipna: bool): tm.assert_almost_equal(result, expected) @pytest.mark.skip("TODO: tests not written yet") - @pytest.mark.parametrize("skipna", [True, False]) def test_reduce_frame(self, data, all_numeric_reductions, skipna): pass diff --git a/pandas/tests/extension/test_sparse.py b/pandas/tests/extension/test_sparse.py index 4039a5d01f372..4c6550ff191a5 100644 --- a/pandas/tests/extension/test_sparse.py +++ b/pandas/tests/extension/test_sparse.py @@ -102,7 +102,6 @@ class TestSparseArray(base.ExtensionTests): def _supports_reduction(self, obj, op_name: str) -> bool: return True - @pytest.mark.parametrize("skipna", [True, False]) def test_reduce_series_numeric(self, data, all_numeric_reductions, skipna, request): if all_numeric_reductions in [ "prod", @@ -127,7 +126,6 @@ def test_reduce_series_numeric(self, data, all_numeric_reductions, skipna, reque super().test_reduce_series_numeric(data, all_numeric_reductions, skipna) - @pytest.mark.parametrize("skipna", [True, False]) def test_reduce_frame(self, data, all_numeric_reductions, skipna, request): if all_numeric_reductions in [ "prod", diff --git a/pandas/tests/frame/test_reductions.py b/pandas/tests/frame/test_reductions.py index 66145c32c18d7..1ef863c02c35e 100644 --- a/pandas/tests/frame/test_reductions.py +++ b/pandas/tests/frame/test_reductions.py @@ -1068,7 +1068,6 @@ def test_sum_bools(self): # ---------------------------------------------------------------------- # Index of max / min - @pytest.mark.parametrize("skipna", [True, False]) @pytest.mark.parametrize("axis", [0, 1]) def test_idxmin(self, float_frame, int_frame, skipna, axis): frame = float_frame @@ -1117,7 +1116,6 @@ def test_idxmin_axis_2(self, float_frame): with pytest.raises(ValueError, match=msg): frame.idxmin(axis=2) - @pytest.mark.parametrize("skipna", [True, False]) @pytest.mark.parametrize("axis", [0, 1]) def test_idxmax(self, float_frame, int_frame, skipna, axis): frame = float_frame @@ -1361,7 +1359,6 @@ def test_any_all_extra(self): @pytest.mark.parametrize("axis", [0, 1]) @pytest.mark.parametrize("bool_agg_func", ["any", "all"]) - @pytest.mark.parametrize("skipna", [True, False]) def test_any_all_object_dtype( self, axis, bool_agg_func, skipna, using_infer_string ): diff --git a/pandas/tests/groupby/test_reductions.py b/pandas/tests/groupby/test_reductions.py index 18d59cd3cd593..c8678156d0c75 100644 --- a/pandas/tests/groupby/test_reductions.py +++ b/pandas/tests/groupby/test_reductions.py @@ -1023,7 +1023,6 @@ def test_apply_to_nullable_integer_returns_float(values, function): ], ) @pytest.mark.parametrize("axis", [0, 1]) -@pytest.mark.parametrize("skipna", [True, False]) def test_regression_allowlist_methods(op, axis, skipna, sort): # GH6944 # GH 17537 diff --git a/pandas/tests/reductions/test_reductions.py b/pandas/tests/reductions/test_reductions.py index 30ec0d0affaa3..27a802d14c23e 100644 --- a/pandas/tests/reductions/test_reductions.py +++ b/pandas/tests/reductions/test_reductions.py @@ -802,7 +802,6 @@ def test_var_masked_array(self, ddof, exp): assert result == exp @pytest.mark.parametrize("dtype", ("m8[ns]", "m8[ns]", "M8[ns]", "M8[ns, UTC]")) - @pytest.mark.parametrize("skipna", [True, False]) def test_empty_timeseries_reductions_return_nat(self, dtype, skipna): # covers GH#11245 assert Series([], dtype=dtype).min(skipna=skipna) is NaT @@ -987,7 +986,6 @@ def test_all_any_bool_only(self): assert not s.all(bool_only=True) @pytest.mark.parametrize("bool_agg_func", ["any", "all"]) - @pytest.mark.parametrize("skipna", [True, False]) def test_any_all_object_dtype(self, bool_agg_func, skipna): # GH#12863 ser = Series(["a", "b", "c", "d", "e"], dtype=object) @@ -1011,7 +1009,6 @@ def test_any_all_object_dtype_missing(self, data, bool_agg_func): @pytest.mark.parametrize("dtype", ["boolean", "Int64", "UInt64", "Float64"]) @pytest.mark.parametrize("bool_agg_func", ["any", "all"]) - @pytest.mark.parametrize("skipna", [True, False]) @pytest.mark.parametrize( # expected_data indexed as [[skipna=False/any, skipna=False/all], # [skipna=True/any, skipna=True/all]] @@ -1380,7 +1377,6 @@ def test_min_max_ordered(self, values, categories, function): assert result == expected @pytest.mark.parametrize("function", ["min", "max"]) - @pytest.mark.parametrize("skipna", [True, False]) def test_min_max_ordered_with_nan_only(self, function, skipna): # https://github.com/pandas-dev/pandas/issues/33450 cat = Series(Categorical([np.nan], categories=[1, 2], ordered=True)) @@ -1388,7 +1384,6 @@ def test_min_max_ordered_with_nan_only(self, function, skipna): assert result is np.nan @pytest.mark.parametrize("function", ["min", "max"]) - @pytest.mark.parametrize("skipna", [True, False]) def test_min_max_skipna(self, function, skipna): cat = Series( Categorical(["a", "b", np.nan, "a"], categories=["b", "a"], ordered=True) diff --git a/pandas/tests/series/test_reductions.py b/pandas/tests/series/test_reductions.py index 76353ab25fca6..0f8627d46067e 100644 --- a/pandas/tests/series/test_reductions.py +++ b/pandas/tests/series/test_reductions.py @@ -70,7 +70,6 @@ def test_reductions_td64_with_nat(): assert ser.max() == exp -@pytest.mark.parametrize("skipna", [True, False]) def test_td64_sum_empty(skipna): # GH#37151 ser = Series([], dtype="timedelta64[ns]") From 4a3cb1372294c15897f3165bf4d997897cab5637 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Wed, 20 Dec 2023 11:55:57 -0800 Subject: [PATCH 06/26] Use top level keep fixture --- pandas/tests/extension/base/methods.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/tests/extension/base/methods.py b/pandas/tests/extension/base/methods.py index c803a8113b4a4..88ef67605de98 100644 --- a/pandas/tests/extension/base/methods.py +++ b/pandas/tests/extension/base/methods.py @@ -248,7 +248,6 @@ def test_sort_values_frame(self, data_for_sorting, ascending): ) tm.assert_frame_equal(result, expected) - @pytest.mark.parametrize("keep", ["first", "last", False]) def test_duplicated(self, data, keep): arr = data.take([0, 1, 0, 1]) result = arr.duplicated(keep=keep) From c9e3a57c1f8adc33a827e1f8f5e22110acc558e8 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Wed, 20 Dec 2023 11:57:35 -0800 Subject: [PATCH 07/26] Use top level closed fixture --- pandas/tests/indexes/interval/test_pickle.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/pandas/tests/indexes/interval/test_pickle.py b/pandas/tests/indexes/interval/test_pickle.py index 308a90e72eab5..c52106e5f0786 100644 --- a/pandas/tests/indexes/interval/test_pickle.py +++ b/pandas/tests/indexes/interval/test_pickle.py @@ -1,11 +1,8 @@ -import pytest - from pandas import IntervalIndex import pandas._testing as tm class TestPickle: - @pytest.mark.parametrize("closed", ["left", "right", "both"]) def test_pickle_round_trip_closed(self, closed): # https://github.com/pandas-dev/pandas/issues/35658 idx = IntervalIndex.from_tuples([(1, 2), (2, 3)], closed=closed) From 84ef346196aba82a008b696d2e48c16b2a318c2e Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Wed, 20 Dec 2023 12:03:26 -0800 Subject: [PATCH 08/26] Use top level writable fixture --- pandas/tests/libs/test_join.py | 10 ++++------ pandas/tests/tools/test_to_datetime.py | 6 ++---- pandas/tests/tools/test_to_timedelta.py | 6 ++---- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/pandas/tests/libs/test_join.py b/pandas/tests/libs/test_join.py index ba2e6e7130929..bf8b4fabc54cb 100644 --- a/pandas/tests/libs/test_join.py +++ b/pandas/tests/libs/test_join.py @@ -138,14 +138,12 @@ def test_cython_inner_join(self): tm.assert_numpy_array_equal(rs, exp_rs) -@pytest.mark.parametrize("readonly", [True, False]) -def test_left_join_indexer_unique(readonly): +def test_left_join_indexer_unique(writable): a = np.array([1, 2, 3, 4, 5], dtype=np.int64) b = np.array([2, 2, 3, 4, 4], dtype=np.int64) - if readonly: - # GH#37312, GH#37264 - a.setflags(write=False) - b.setflags(write=False) + # GH#37312, GH#37264 + a.setflags(write=writable) + b.setflags(write=writable) result = libjoin.left_join_indexer_unique(b, a) expected = np.array([1, 1, 2, 3, 3], dtype=np.intp) diff --git a/pandas/tests/tools/test_to_datetime.py b/pandas/tests/tools/test_to_datetime.py index a23d2d3dc22af..0ce1f7b0ff20e 100644 --- a/pandas/tests/tools/test_to_datetime.py +++ b/pandas/tests/tools/test_to_datetime.py @@ -71,12 +71,10 @@ def cache(request): class TestTimeConversionFormats: - @pytest.mark.parametrize("readonly", [True, False]) - def test_to_datetime_readonly(self, readonly): + def test_to_datetime_readonly(self, writable): # GH#34857 arr = np.array([], dtype=object) - if readonly: - arr.setflags(write=False) + arr.setflags(write=writable) result = to_datetime(arr) expected = to_datetime([]) tm.assert_index_equal(result, expected) diff --git a/pandas/tests/tools/test_to_timedelta.py b/pandas/tests/tools/test_to_timedelta.py index b67694f1c58c7..036462674c270 100644 --- a/pandas/tests/tools/test_to_timedelta.py +++ b/pandas/tests/tools/test_to_timedelta.py @@ -32,12 +32,10 @@ def test_to_timedelta_dt64_raises(self): with pytest.raises(TypeError, match=msg): ser.to_frame().apply(to_timedelta) - @pytest.mark.parametrize("readonly", [True, False]) - def test_to_timedelta_readonly(self, readonly): + def test_to_timedelta_readonly(self, writable): # GH#34857 arr = np.array([], dtype=object) - if readonly: - arr.setflags(write=False) + arr.setflags(write=writable) result = to_timedelta(arr) expected = to_timedelta([]) tm.assert_index_equal(result, expected) From 39ab4b4951b85041812f1e9cc6c2b8b486c41903 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Wed, 20 Dec 2023 12:05:17 -0800 Subject: [PATCH 09/26] Use top level other_closed --- pandas/tests/arrays/interval/test_interval.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pandas/tests/arrays/interval/test_interval.py b/pandas/tests/arrays/interval/test_interval.py index be4b2c3e7e74c..58ba340441d86 100644 --- a/pandas/tests/arrays/interval/test_interval.py +++ b/pandas/tests/arrays/interval/test_interval.py @@ -58,12 +58,11 @@ def test_is_empty(self, constructor, left, right, closed): class TestMethods: - @pytest.mark.parametrize("new_closed", ["left", "right", "both", "neither"]) - def test_set_closed(self, closed, new_closed): + def test_set_closed(self, closed, other_closed): # GH 21670 array = IntervalArray.from_breaks(range(10), closed=closed) - result = array.set_closed(new_closed) - expected = IntervalArray.from_breaks(range(10), closed=new_closed) + result = array.set_closed(other_closed) + expected = IntervalArray.from_breaks(range(10), closed=other_closed) tm.assert_extension_array_equal(result, expected) @pytest.mark.parametrize( From 0c4829b8c22c251edb5699cf4697ec8ef0840913 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Wed, 20 Dec 2023 12:10:12 -0800 Subject: [PATCH 10/26] Use top level join_type fixture --- pandas/tests/frame/methods/test_align.py | 12 ++++++++++-- pandas/tests/indexes/datetimes/test_date_range.py | 5 ++--- pandas/tests/indexes/interval/test_indexing.py | 1 - pandas/tests/indexes/interval/test_interval.py | 7 +++---- pandas/tests/reshape/merge/test_merge.py | 15 ++++++++++----- pandas/tests/test_sorting.py | 9 ++++----- 6 files changed, 29 insertions(+), 20 deletions(-) diff --git a/pandas/tests/frame/methods/test_align.py b/pandas/tests/frame/methods/test_align.py index 5a9c47866dae8..1f5d960de40c1 100644 --- a/pandas/tests/frame/methods/test_align.py +++ b/pandas/tests/frame/methods/test_align.py @@ -395,7 +395,6 @@ def test_missing_axis_specification_exception(self): @pytest.mark.parametrize("method", ["pad", "bfill"]) @pytest.mark.parametrize("axis", [0, 1, None]) @pytest.mark.parametrize("fill_axis", [0, 1]) - @pytest.mark.parametrize("how", ["inner", "outer", "left", "right"]) @pytest.mark.parametrize( "left_slice", [ @@ -412,8 +411,17 @@ def test_missing_axis_specification_exception(self): ) @pytest.mark.parametrize("limit", [1, None]) def test_align_fill_method( - self, how, method, axis, fill_axis, float_frame, left_slice, right_slice, limit + self, + join_type, + method, + axis, + fill_axis, + float_frame, + left_slice, + right_slice, + limit, ): + how = join_type frame = float_frame left = frame.iloc[left_slice[0], left_slice[1]] right = frame.iloc[right_slice[0], right_slice[1]] diff --git a/pandas/tests/indexes/datetimes/test_date_range.py b/pandas/tests/indexes/datetimes/test_date_range.py index 44dd64e162413..019d434680661 100644 --- a/pandas/tests/indexes/datetimes/test_date_range.py +++ b/pandas/tests/indexes/datetimes/test_date_range.py @@ -1093,12 +1093,11 @@ def test_daterange_bug_456(self): result = rng1.union(rng2) assert isinstance(result, DatetimeIndex) - @pytest.mark.parametrize("inclusive", ["left", "right", "neither", "both"]) - def test_bdays_and_open_boundaries(self, inclusive): + def test_bdays_and_open_boundaries(self, inclusive_endpoints_fixture): # GH 6673 start = "2018-07-21" # Saturday end = "2018-07-29" # Sunday - result = date_range(start, end, freq="B", inclusive=inclusive) + result = date_range(start, end, freq="B", inclusive=inclusive_endpoints_fixture) bday_start = "2018-07-23" # Monday bday_end = "2018-07-27" # Friday diff --git a/pandas/tests/indexes/interval/test_indexing.py b/pandas/tests/indexes/interval/test_indexing.py index fd03047b2c127..787461b944bd0 100644 --- a/pandas/tests/indexes/interval/test_indexing.py +++ b/pandas/tests/indexes/interval/test_indexing.py @@ -141,7 +141,6 @@ def test_get_loc_length_one_scalar(self, scalar, closed): with pytest.raises(KeyError, match=str(scalar)): index.get_loc(scalar) - @pytest.mark.parametrize("other_closed", ["left", "right", "both", "neither"]) @pytest.mark.parametrize("left, right", [(0, 5), (-1, 4), (-1, 6), (6, 7)]) def test_get_loc_length_one_interval(self, left, right, closed, other_closed): # GH 20921 diff --git a/pandas/tests/indexes/interval/test_interval.py b/pandas/tests/indexes/interval/test_interval.py index 63f9b2176dddd..89b991318be0d 100644 --- a/pandas/tests/indexes/interval/test_interval.py +++ b/pandas/tests/indexes/interval/test_interval.py @@ -865,12 +865,11 @@ def test_nbytes(self): expected = 64 # 4 * 8 * 2 assert result == expected - @pytest.mark.parametrize("new_closed", ["left", "right", "both", "neither"]) - def test_set_closed(self, name, closed, new_closed): + def test_set_closed(self, name, closed, other_closed): # GH 21670 index = interval_range(0, 5, closed=closed, name=name) - result = index.set_closed(new_closed) - expected = interval_range(0, 5, closed=new_closed, name=name) + result = index.set_closed(other_closed) + expected = interval_range(0, 5, closed=other_closed, name=name) tm.assert_index_equal(result, expected) @pytest.mark.parametrize("bad_closed", ["foo", 10, "LEFT", True, False]) diff --git a/pandas/tests/reshape/merge/test_merge.py b/pandas/tests/reshape/merge/test_merge.py index 3c0965308f8b7..d745367dac3a5 100644 --- a/pandas/tests/reshape/merge/test_merge.py +++ b/pandas/tests/reshape/merge/test_merge.py @@ -455,13 +455,12 @@ def test_left_merge_empty_dataframe(self): result = merge(right, left, on="key", how="right") tm.assert_frame_equal(result, left) - @pytest.mark.parametrize("how", ["inner", "left", "right", "outer"]) - def test_merge_empty_dataframe(self, index, how): + def test_merge_empty_dataframe(self, index, join_type): # GH52777 left = DataFrame([], index=index[:0]) right = left.copy() - result = left.join(right, how=how) + result = left.join(right, how=join_type) tm.assert_frame_equal(result, left) @pytest.mark.parametrize( @@ -2859,15 +2858,21 @@ def test_merge_multiindex_single_level(): tm.assert_frame_equal(result, expected) -@pytest.mark.parametrize("how", ["left", "right", "inner", "outer"]) @pytest.mark.parametrize("on_index", [True, False]) @pytest.mark.parametrize("left_unique", [True, False]) @pytest.mark.parametrize("left_monotonic", [True, False]) @pytest.mark.parametrize("right_unique", [True, False]) @pytest.mark.parametrize("right_monotonic", [True, False]) def test_merge_combinations( - how, sort, on_index, left_unique, left_monotonic, right_unique, right_monotonic + join_type, + sort, + on_index, + left_unique, + left_monotonic, + right_unique, + right_monotonic, ): + how = join_type # GH 54611 left = [2, 3] if left_unique: diff --git a/pandas/tests/test_sorting.py b/pandas/tests/test_sorting.py index e692d8326c5ba..329fbac925539 100644 --- a/pandas/tests/test_sorting.py +++ b/pandas/tests/test_sorting.py @@ -218,14 +218,13 @@ def test_int64_overflow_check_sum_col(self, left_right): assert result.name is None @pytest.mark.slow - @pytest.mark.parametrize("how", ["left", "right", "outer", "inner"]) - def test_int64_overflow_how_merge(self, left_right, how): + def test_int64_overflow_how_merge(self, left_right, join_type): left, right = left_right out = merge(left, right, how="outer") out.sort_values(out.columns.tolist(), inplace=True) out.index = np.arange(len(out)) - tm.assert_frame_equal(out, merge(left, right, how=how, sort=True)) + tm.assert_frame_equal(out, merge(left, right, how=join_type, sort=True)) @pytest.mark.slow def test_int64_overflow_sort_false_order(self, left_right): @@ -239,9 +238,9 @@ def test_int64_overflow_sort_false_order(self, left_right): tm.assert_frame_equal(right, out[right.columns.tolist()]) @pytest.mark.slow - @pytest.mark.parametrize("how", ["left", "right", "outer", "inner"]) - def test_int64_overflow_one_to_many_none_match(self, how, sort): + def test_int64_overflow_one_to_many_none_match(self, join_type, sort): # one-2-many/none match + how = join_type low, high, n = -1 << 10, 1 << 10, 1 << 11 left = DataFrame( np.random.default_rng(2).integers(low, high, (n, 7)).astype("int64"), From 45c02afaf8dafcaf04b62015e194c8ea3682fab9 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Wed, 20 Dec 2023 12:11:17 -0800 Subject: [PATCH 11/26] use another join_type --- pandas/tests/reshape/merge/test_merge.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pandas/tests/reshape/merge/test_merge.py b/pandas/tests/reshape/merge/test_merge.py index d745367dac3a5..3382ed27a90a7 100644 --- a/pandas/tests/reshape/merge/test_merge.py +++ b/pandas/tests/reshape/merge/test_merge.py @@ -2818,9 +2818,8 @@ def test_merge_arrow_and_numpy_dtypes(dtype): tm.assert_frame_equal(result, expected) -@pytest.mark.parametrize("how", ["inner", "left", "outer", "right"]) @pytest.mark.parametrize("tz", [None, "America/Chicago"]) -def test_merge_datetime_different_resolution(tz, how): +def test_merge_datetime_different_resolution(tz, join_type): # https://github.com/pandas-dev/pandas/issues/53200 vals = [ pd.Timestamp(2023, 5, 12, tz=tz), @@ -2834,14 +2833,14 @@ def test_merge_datetime_different_resolution(tz, how): expected = DataFrame({"t": vals, "a": [1.0, 2.0, np.nan], "b": [np.nan, 1.0, 2.0]}) expected["t"] = expected["t"].dt.as_unit("ns") - if how == "inner": + if join_type == "inner": expected = expected.iloc[[1]].reset_index(drop=True) - elif how == "left": + elif join_type == "left": expected = expected.iloc[[0, 1]] - elif how == "right": + elif join_type == "right": expected = expected.iloc[[1, 2]].reset_index(drop=True) - result = df1.merge(df2, on="t", how=how) + result = df1.merge(df2, on="t", how=join_type) tm.assert_frame_equal(result, expected) From 4dd414b175f769e93a43288ac3da27624cc1bc19 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Wed, 20 Dec 2023 12:15:33 -0800 Subject: [PATCH 12/26] Use another join_type --- pandas/tests/strings/test_cat.py | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/pandas/tests/strings/test_cat.py b/pandas/tests/strings/test_cat.py index 284932491a65e..f54feabe49007 100644 --- a/pandas/tests/strings/test_cat.py +++ b/pandas/tests/strings/test_cat.py @@ -259,14 +259,13 @@ def test_str_cat_mixed_inputs(index_or_series): s.str.cat(iter([t.values, list(s)])) -@pytest.mark.parametrize("join", ["left", "outer", "inner", "right"]) -def test_str_cat_align_indexed(index_or_series, join): +def test_str_cat_align_indexed(index_or_series, join_type): # https://github.com/pandas-dev/pandas/issues/18657 box = index_or_series s = Series(["a", "b", "c", "d"], index=["a", "b", "c", "d"]) t = Series(["D", "A", "E", "B"], index=["d", "a", "e", "b"]) - sa, ta = s.align(t, join=join) + sa, ta = s.align(t, join=join_type) # result after manual alignment of inputs expected = sa.str.cat(ta, na_rep="-") @@ -275,25 +274,24 @@ def test_str_cat_align_indexed(index_or_series, join): sa = Index(sa) expected = Index(expected) - result = s.str.cat(t, join=join, na_rep="-") + result = s.str.cat(t, join=join_type, na_rep="-") tm.assert_equal(result, expected) -@pytest.mark.parametrize("join", ["left", "outer", "inner", "right"]) -def test_str_cat_align_mixed_inputs(join): +def test_str_cat_align_mixed_inputs(join_type): s = Series(["a", "b", "c", "d"]) t = Series(["d", "a", "e", "b"], index=[3, 0, 4, 1]) d = concat([t, t], axis=1) expected_outer = Series(["aaa", "bbb", "c--", "ddd", "-ee"]) - expected = expected_outer.loc[s.index.join(t.index, how=join)] + expected = expected_outer.loc[s.index.join(t.index, how=join_type)] # list of Series - result = s.str.cat([t, t], join=join, na_rep="-") + result = s.str.cat([t, t], join=join_type, na_rep="-") tm.assert_series_equal(result, expected) # DataFrame - result = s.str.cat(d, join=join, na_rep="-") + result = s.str.cat(d, join=join_type, na_rep="-") tm.assert_series_equal(result, expected) # mixed list of indexed/unindexed @@ -302,19 +300,19 @@ def test_str_cat_align_mixed_inputs(join): # joint index of rhs [t, u]; u will be forced have index of s rhs_idx = ( t.index.intersection(s.index) - if join == "inner" + if join_type == "inner" else t.index.union(s.index) - if join == "outer" + if join_type == "outer" else t.index.append(s.index.difference(t.index)) ) - expected = expected_outer.loc[s.index.join(rhs_idx, how=join)] - result = s.str.cat([t, u], join=join, na_rep="-") + expected = expected_outer.loc[s.index.join(rhs_idx, how=join_type)] + result = s.str.cat([t, u], join=join_type, na_rep="-") tm.assert_series_equal(result, expected) with pytest.raises(TypeError, match="others must be Series,.*"): # nested lists are forbidden - s.str.cat([t, list(u)], join=join) + s.str.cat([t, list(u)], join=join_type) # errors for incorrect lengths rgx = r"If `others` contains arrays or lists \(or other list-likes.*" @@ -322,11 +320,11 @@ def test_str_cat_align_mixed_inputs(join): # unindexed object of wrong length with pytest.raises(ValueError, match=rgx): - s.str.cat(z, join=join) + s.str.cat(z, join=join_type) # unindexed object of wrong length in list with pytest.raises(ValueError, match=rgx): - s.str.cat([t, z], join=join) + s.str.cat([t, z], join=join_type) def test_str_cat_all_na(index_or_series, index_or_series2): From f37f7b236dbb357c6267cee8e0d7d50dc80d6f7f Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Wed, 20 Dec 2023 12:17:50 -0800 Subject: [PATCH 13/26] use top level nselect_method --- pandas/tests/groupby/methods/test_nlargest_nsmallest.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pandas/tests/groupby/methods/test_nlargest_nsmallest.py b/pandas/tests/groupby/methods/test_nlargest_nsmallest.py index bf983f04a3f3f..1225c325c4c23 100644 --- a/pandas/tests/groupby/methods/test_nlargest_nsmallest.py +++ b/pandas/tests/groupby/methods/test_nlargest_nsmallest.py @@ -99,17 +99,16 @@ def test_nsmallest(): [([0, 1, 2, 3], [0, 0, 1, 1]), ([0], [0])], ) @pytest.mark.parametrize("dtype", [None, *tm.ALL_INT_NUMPY_DTYPES]) -@pytest.mark.parametrize("method", ["nlargest", "nsmallest"]) -def test_nlargest_and_smallest_noop(data, groups, dtype, method): +def test_nlargest_and_smallest_noop(data, groups, dtype, nselect_method): # GH 15272, GH 16345, GH 29129 # Test nlargest/smallest when it results in a noop, # i.e. input is sorted and group size <= n if dtype is not None: data = np.array(data, dtype=dtype) - if method == "nlargest": + if nselect_method == "nlargest": data = list(reversed(data)) ser = Series(data, name="a") - result = getattr(ser.groupby(groups), method)(n=2) + result = getattr(ser.groupby(groups), nselect_method)(n=2) expidx = np.array(groups, dtype=int) if isinstance(groups, list) else groups expected = Series(data, index=MultiIndex.from_arrays([expidx, ser.index]), name="a") tm.assert_series_equal(result, expected) From c78ede633937fdfdf420e1564289f6c62c9abdc9 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Wed, 20 Dec 2023 13:11:00 -0800 Subject: [PATCH 14/26] Reuse all_boolean_reductions --- pandas/conftest.py | 4 -- pandas/tests/dtypes/test_inference.py | 4 +- pandas/tests/frame/test_reductions.py | 47 +++++++++++----------- pandas/tests/groupby/test_reductions.py | 40 +++++++++--------- pandas/tests/indexes/test_base.py | 9 ++--- pandas/tests/reductions/test_reductions.py | 19 ++++----- pandas/tests/strings/test_cat.py | 5 +++ 7 files changed, 60 insertions(+), 68 deletions(-) diff --git a/pandas/conftest.py b/pandas/conftest.py index 51bf494361862..85443843b041e 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -483,10 +483,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): """ diff --git a/pandas/tests/dtypes/test_inference.py b/pandas/tests/dtypes/test_inference.py index 82db41de27117..8c3407deb9292 100644 --- a/pandas/tests/dtypes/test_inference.py +++ b/pandas/tests/dtypes/test_inference.py @@ -1339,8 +1339,8 @@ def test_infer_dtype_period(self): arr = np.array([Period("2011-01", freq="D"), Period("2011-02", freq="M")]) assert lib.infer_dtype(arr, skipna=True) == "mixed" - @pytest.mark.parametrize("klass", [pd.array, Series, Index]) - def test_infer_dtype_period_array(self, klass, skipna): + def test_infer_dtype_period_array(self, index_or_series_or_array, skipna): + klass = index_or_series_or_array # https://github.com/pandas-dev/pandas/issues/23553 values = klass( [ diff --git a/pandas/tests/frame/test_reductions.py b/pandas/tests/frame/test_reductions.py index 1ef863c02c35e..04ba3bc70daa5 100644 --- a/pandas/tests/frame/test_reductions.py +++ b/pandas/tests/frame/test_reductions.py @@ -1264,29 +1264,30 @@ def test_idxmax_dt64_multicolumn_axis1(self): # ---------------------------------------------------------------------- # Logical reductions - @pytest.mark.parametrize("opname", ["any", "all"]) @pytest.mark.parametrize("axis", [0, 1]) @pytest.mark.parametrize("bool_only", [False, True]) - def test_any_all_mixed_float(self, opname, axis, bool_only, float_string_frame): + def test_any_all_mixed_float( + self, all_boolean_reductions, axis, bool_only, float_string_frame + ): # make sure op works on mixed-type frame mixed = float_string_frame mixed["_bool_"] = np.random.default_rng(2).standard_normal(len(mixed)) > 0.5 - getattr(mixed, opname)(axis=axis, bool_only=bool_only) + getattr(mixed, all_boolean_reductions)(axis=axis, bool_only=bool_only) - @pytest.mark.parametrize("opname", ["any", "all"]) @pytest.mark.parametrize("axis", [0, 1]) - def test_any_all_bool_with_na(self, opname, axis, bool_frame_with_na): - getattr(bool_frame_with_na, opname)(axis=axis, bool_only=False) + def test_any_all_bool_with_na( + self, all_boolean_reductions, axis, bool_frame_with_na + ): + getattr(bool_frame_with_na, all_boolean_reductions)(axis=axis, bool_only=False) @pytest.mark.filterwarnings("ignore:Downcasting object dtype arrays:FutureWarning") - @pytest.mark.parametrize("opname", ["any", "all"]) - def test_any_all_bool_frame(self, opname, bool_frame_with_na): + def test_any_all_bool_frame(self, all_boolean_reductions, bool_frame_with_na): # GH#12863: numpy gives back non-boolean data for object type # so fill NaNs to compare with pandas behavior frame = bool_frame_with_na.fillna(True) - alternative = getattr(np, opname) - f = getattr(frame, opname) + alternative = getattr(np, all_boolean_reductions) + f = getattr(frame, all_boolean_reductions) def skipna_wrapper(x): nona = x.dropna().values @@ -1315,9 +1316,9 @@ def wrapper(x): # all NA case all_na = frame * np.nan - r0 = getattr(all_na, opname)(axis=0) - r1 = getattr(all_na, opname)(axis=1) - if opname == "any": + r0 = getattr(all_na, all_boolean_reductions)(axis=0) + r1 = getattr(all_na, all_boolean_reductions)(axis=1) + if all_boolean_reductions == "any": assert not r0.any() assert not r1.any() else: @@ -1358,9 +1359,8 @@ def test_any_all_extra(self): assert result is True @pytest.mark.parametrize("axis", [0, 1]) - @pytest.mark.parametrize("bool_agg_func", ["any", "all"]) def test_any_all_object_dtype( - self, axis, bool_agg_func, skipna, using_infer_string + self, axis, all_boolean_reductions, skipna, using_infer_string ): # GH#35450 df = DataFrame( @@ -1373,10 +1373,10 @@ def test_any_all_object_dtype( ) if using_infer_string: # na in object is True while in string pyarrow numpy it's false - val = not axis == 0 and not skipna and bool_agg_func == "all" + val = not axis == 0 and not skipna and all_boolean_reductions == "all" else: val = True - result = getattr(df, bool_agg_func)(axis=axis, skipna=skipna) + result = getattr(df, all_boolean_reductions)(axis=axis, skipna=skipna) expected = Series([True, True, val, True]) tm.assert_series_equal(result, expected) @@ -1745,27 +1745,26 @@ def test_reduction_timedelta_smallest_unit(self): class TestNuisanceColumns: - @pytest.mark.parametrize("method", ["any", "all"]) - def test_any_all_categorical_dtype_nuisance_column(self, method): + def test_any_all_categorical_dtype_nuisance_column(self, all_boolean_reductions): # GH#36076 DataFrame should match Series behavior ser = Series([0, 1], dtype="category", name="A") df = ser.to_frame() # Double-check the Series behavior is to raise with pytest.raises(TypeError, match="does not support reduction"): - getattr(ser, method)() + getattr(ser, all_boolean_reductions)() with pytest.raises(TypeError, match="does not support reduction"): - getattr(np, method)(ser) + getattr(np, all_boolean_reductions)(ser) with pytest.raises(TypeError, match="does not support reduction"): - getattr(df, method)(bool_only=False) + getattr(df, all_boolean_reductions)(bool_only=False) with pytest.raises(TypeError, match="does not support reduction"): - getattr(df, method)(bool_only=None) + getattr(df, all_boolean_reductions)(bool_only=None) with pytest.raises(TypeError, match="does not support reduction"): - getattr(np, method)(df, axis=0) + getattr(np, all_boolean_reductions)(df, axis=0) def test_median_categorical_dtype_nuisance_column(self): # GH#21020 DataFrame.median should match Series.median diff --git a/pandas/tests/groupby/test_reductions.py b/pandas/tests/groupby/test_reductions.py index c8678156d0c75..ba73bf3b9908a 100644 --- a/pandas/tests/groupby/test_reductions.py +++ b/pandas/tests/groupby/test_reductions.py @@ -20,7 +20,6 @@ from pandas.util import _test_decorators as td -@pytest.mark.parametrize("agg_func", ["any", "all"]) @pytest.mark.parametrize( "vals", [ @@ -39,20 +38,20 @@ [np.nan, np.nan, np.nan], ], ) -def test_groupby_bool_aggs(skipna, agg_func, vals): +def test_groupby_bool_aggs(skipna, all_boolean_reductions, vals): df = DataFrame({"key": ["a"] * 3 + ["b"] * 3, "val": vals * 2}) # Figure out expectation using Python builtin - exp = getattr(builtins, agg_func)(vals) + exp = getattr(builtins, all_boolean_reductions)(vals) # edge case for missing data with skipna and 'any' - if skipna and all(isna(vals)) and agg_func == "any": + if skipna and all(isna(vals)) and all_boolean_reductions == "any": exp = False expected = DataFrame( [exp] * 2, columns=["val"], index=pd.Index(["a", "b"], name="key") ) - result = getattr(df.groupby("key"), agg_func)(skipna=skipna) + result = getattr(df.groupby("key"), all_boolean_reductions)(skipna=skipna) tm.assert_frame_equal(result, expected) @@ -69,18 +68,16 @@ def test_any(): tm.assert_frame_equal(result, expected) -@pytest.mark.parametrize("bool_agg_func", ["any", "all"]) -def test_bool_aggs_dup_column_labels(bool_agg_func): +def test_bool_aggs_dup_column_labels(all_boolean_reductions): # GH#21668 df = DataFrame([[True, True]], columns=["a", "a"]) grp_by = df.groupby([0]) - result = getattr(grp_by, bool_agg_func)() + result = getattr(grp_by, all_boolean_reductions)() expected = df.set_axis(np.array([0])) tm.assert_frame_equal(result, expected) -@pytest.mark.parametrize("bool_agg_func", ["any", "all"]) @pytest.mark.parametrize( "data", [ @@ -92,16 +89,16 @@ def test_bool_aggs_dup_column_labels(bool_agg_func): [True, pd.NA, False], ], ) -def test_masked_kleene_logic(bool_agg_func, skipna, data): +def test_masked_kleene_logic(all_boolean_reductions, skipna, data): # GH#37506 ser = Series(data, dtype="boolean") # The result should match aggregating on the whole series. Correctness # there is verified in test_reductions.py::test_any_all_boolean_kleene_logic - expected_data = getattr(ser, bool_agg_func)(skipna=skipna) + expected_data = getattr(ser, all_boolean_reductions)(skipna=skipna) expected = Series(expected_data, index=np.array([0]), dtype="boolean") - result = ser.groupby([0, 0, 0]).agg(bool_agg_func, skipna=skipna) + result = ser.groupby([0, 0, 0]).agg(all_boolean_reductions, skipna=skipna) tm.assert_series_equal(result, expected) @@ -146,17 +143,18 @@ def test_masked_mixed_types(dtype1, dtype2, exp_col1, exp_col2): tm.assert_frame_equal(result, expected) -@pytest.mark.parametrize("bool_agg_func", ["any", "all"]) @pytest.mark.parametrize("dtype", ["Int64", "Float64", "boolean"]) -def test_masked_bool_aggs_skipna(bool_agg_func, dtype, skipna, frame_or_series): +def test_masked_bool_aggs_skipna( + all_boolean_reductions, dtype, skipna, frame_or_series +): # GH#40585 obj = frame_or_series([pd.NA, 1], dtype=dtype) expected_res = True - if not skipna and bool_agg_func == "all": + if not skipna and all_boolean_reductions == "all": expected_res = pd.NA expected = frame_or_series([expected_res], index=np.array([1]), dtype="boolean") - result = obj.groupby([1, 1]).agg(bool_agg_func, skipna=skipna) + result = obj.groupby([1, 1]).agg(all_boolean_reductions, skipna=skipna) tm.assert_equal(result, expected) @@ -177,20 +175,18 @@ def test_object_type_missing_vals(bool_agg_func, data, expected_res, frame_or_se tm.assert_equal(result, expected) -@pytest.mark.parametrize("bool_agg_func", ["any", "all"]) -def test_object_NA_raises_with_skipna_false(bool_agg_func): +def test_object_NA_raises_with_skipna_false(all_boolean_reductions): # GH#37501 ser = Series([pd.NA], dtype=object) with pytest.raises(TypeError, match="boolean value of NA is ambiguous"): - ser.groupby([1]).agg(bool_agg_func, skipna=False) + ser.groupby([1]).agg(all_boolean_reductions, skipna=False) -@pytest.mark.parametrize("bool_agg_func", ["any", "all"]) -def test_empty(frame_or_series, bool_agg_func): +def test_empty(frame_or_series, all_boolean_reductions): # GH 45231 kwargs = {"columns": ["a"]} if frame_or_series is DataFrame else {"name": "a"} obj = frame_or_series(**kwargs, dtype=object) - result = getattr(obj.groupby(obj.index), bool_agg_func)() + result = getattr(obj.groupby(obj.index), all_boolean_reductions)() expected = frame_or_series(**kwargs, dtype=bool) tm.assert_equal(result, expected) diff --git a/pandas/tests/indexes/test_base.py b/pandas/tests/indexes/test_base.py index 185e34efdc177..8cafb089ae69c 100644 --- a/pandas/tests/indexes/test_base.py +++ b/pandas/tests/indexes/test_base.py @@ -720,12 +720,11 @@ def test_format_missing(self, vals, nulls_fixture): assert formatted == expected assert index[3] is nulls_fixture - @pytest.mark.parametrize("op", ["any", "all"]) - def test_logical_compat(self, op, simple_index): + def test_logical_compat(self, all_boolean_reductions, simple_index): index = simple_index - left = getattr(index, op)() - assert left == getattr(index.values, op)() - right = getattr(index.to_series(), op)() + left = getattr(index, all_boolean_reductions)() + assert left == getattr(index.values, all_boolean_reductions)() + right = getattr(index.to_series(), all_boolean_reductions)() # left might not match right exactly in e.g. string cases where the # because we use np.any/all instead of .any/all assert bool(left) == bool(right) diff --git a/pandas/tests/reductions/test_reductions.py b/pandas/tests/reductions/test_reductions.py index 27a802d14c23e..fcb5b65e59402 100644 --- a/pandas/tests/reductions/test_reductions.py +++ b/pandas/tests/reductions/test_reductions.py @@ -985,30 +985,27 @@ def test_all_any_bool_only(self): assert s.any(bool_only=True) assert not s.all(bool_only=True) - @pytest.mark.parametrize("bool_agg_func", ["any", "all"]) - def test_any_all_object_dtype(self, bool_agg_func, skipna): + def test_any_all_object_dtype(self, all_boolean_reductions, skipna): # GH#12863 ser = Series(["a", "b", "c", "d", "e"], dtype=object) - result = getattr(ser, bool_agg_func)(skipna=skipna) + result = getattr(ser, all_boolean_reductions)(skipna=skipna) expected = True assert result == expected - @pytest.mark.parametrize("bool_agg_func", ["any", "all"]) @pytest.mark.parametrize( "data", [[False, None], [None, False], [False, np.nan], [np.nan, False]] ) - def test_any_all_object_dtype_missing(self, data, bool_agg_func): + def test_any_all_object_dtype_missing(self, data, all_boolean_reductions): # GH#27709 ser = Series(data) - result = getattr(ser, bool_agg_func)(skipna=False) + result = getattr(ser, all_boolean_reductions)(skipna=False) # None is treated is False, but np.nan is treated as True - expected = bool_agg_func == "any" and None not in data + expected = all_boolean_reductions == "any" and None not in data assert result == expected @pytest.mark.parametrize("dtype", ["boolean", "Int64", "UInt64", "Float64"]) - @pytest.mark.parametrize("bool_agg_func", ["any", "all"]) @pytest.mark.parametrize( # expected_data indexed as [[skipna=False/any, skipna=False/all], # [skipna=True/any, skipna=True/all]] @@ -1023,13 +1020,13 @@ def test_any_all_object_dtype_missing(self, data, bool_agg_func): ], ) def test_any_all_nullable_kleene_logic( - self, bool_agg_func, skipna, data, dtype, expected_data + self, all_boolean_reductions, skipna, data, dtype, expected_data ): # GH-37506, GH-41967 ser = Series(data, dtype=dtype) - expected = expected_data[skipna][bool_agg_func == "all"] + expected = expected_data[skipna][all_boolean_reductions == "all"] - result = getattr(ser, bool_agg_func)(skipna=skipna) + result = getattr(ser, all_boolean_reductions)(skipna=skipna) assert (result is pd.NA and expected is pd.NA) or result == expected def test_any_axis1_bool_only(self): diff --git a/pandas/tests/strings/test_cat.py b/pandas/tests/strings/test_cat.py index f54feabe49007..26da2d2718f20 100644 --- a/pandas/tests/strings/test_cat.py +++ b/pandas/tests/strings/test_cat.py @@ -16,6 +16,11 @@ ) +@pytest.fixture +def index_or_series2(index_or_series): + return index_or_series + + @pytest.mark.parametrize("other", [None, Series, Index]) def test_str_cat_name(index_or_series, other): # GH 21053 From 33a2697685d079eb34c0b05e19d3b8769f882a80 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Wed, 20 Dec 2023 13:15:57 -0800 Subject: [PATCH 15/26] reuse all_numeric_accumulations --- pandas/tests/frame/test_cumulative.py | 16 +++++++++------- pandas/tests/groupby/transform/test_transform.py | 5 ++--- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/pandas/tests/frame/test_cumulative.py b/pandas/tests/frame/test_cumulative.py index 5bd9c42612315..d7aad680d389e 100644 --- a/pandas/tests/frame/test_cumulative.py +++ b/pandas/tests/frame/test_cumulative.py @@ -7,7 +7,6 @@ """ import numpy as np -import pytest from pandas import ( DataFrame, @@ -46,20 +45,23 @@ def test_cumprod_smoke(self, datetime_frame): df.cumprod(0) df.cumprod(1) - @pytest.mark.parametrize("method", ["cumsum", "cumprod", "cummin", "cummax"]) - def test_cumulative_ops_match_series_apply(self, datetime_frame, method): + def test_cumulative_ops_match_series_apply( + self, datetime_frame, all_numeric_accumulations + ): datetime_frame.iloc[5:10, 0] = np.nan datetime_frame.iloc[10:15, 1] = np.nan datetime_frame.iloc[15:, 2] = np.nan # axis = 0 - result = getattr(datetime_frame, method)() - expected = datetime_frame.apply(getattr(Series, method)) + result = getattr(datetime_frame, all_numeric_accumulations)() + expected = datetime_frame.apply(getattr(Series, all_numeric_accumulations)) tm.assert_frame_equal(result, expected) # axis = 1 - result = getattr(datetime_frame, method)(axis=1) - expected = datetime_frame.apply(getattr(Series, method), axis=1) + result = getattr(datetime_frame, all_numeric_accumulations)(axis=1) + expected = datetime_frame.apply( + getattr(Series, all_numeric_accumulations), axis=1 + ) tm.assert_frame_equal(result, expected) # fix issue TODO: GH ref? diff --git a/pandas/tests/groupby/transform/test_transform.py b/pandas/tests/groupby/transform/test_transform.py index a2ecd6c65db60..f7a4233b3ddc9 100644 --- a/pandas/tests/groupby/transform/test_transform.py +++ b/pandas/tests/groupby/transform/test_transform.py @@ -1239,15 +1239,14 @@ def test_groupby_transform_dtype(): tm.assert_series_equal(result, expected1) -@pytest.mark.parametrize("func", ["cumsum", "cumprod", "cummin", "cummax"]) -def test_transform_absent_categories(func): +def test_transform_absent_categories(all_numeric_accumulations): # GH 16771 # cython transforms with more groups than rows x_vals = [1] x_cats = range(2) y = [1] df = DataFrame({"x": Categorical(x_vals, x_cats), "y": y}) - result = getattr(df.y.groupby(df.x, observed=False), func)() + result = getattr(df.y.groupby(df.x, observed=False), all_numeric_accumulations)() expected = df.y tm.assert_series_equal(result, expected) From 1dd3383de9431d0c25f2b6ba06a2db6250a9db67 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Wed, 20 Dec 2023 13:24:03 -0800 Subject: [PATCH 16/26] Use shared na_action fixture --- pandas/conftest.py | 8 ++++++++ pandas/tests/arrays/categorical/test_map.py | 5 ----- pandas/tests/extension/base/methods.py | 1 - pandas/tests/extension/test_arrow.py | 1 - pandas/tests/extension/test_categorical.py | 1 - pandas/tests/extension/test_datetime.py | 1 - pandas/tests/extension/test_masked.py | 1 - pandas/tests/extension/test_period.py | 1 - pandas/tests/extension/test_sparse.py | 1 - pandas/tests/frame/methods/test_map.py | 1 - pandas/tests/series/methods/test_map.py | 4 ---- 11 files changed, 8 insertions(+), 17 deletions(-) diff --git a/pandas/conftest.py b/pandas/conftest.py index 85443843b041e..b19c3b9ded82f 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -419,6 +419,14 @@ 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 + + # ---------------------------------------------------------------- # Missing values & co. # ---------------------------------------------------------------- diff --git a/pandas/tests/arrays/categorical/test_map.py b/pandas/tests/arrays/categorical/test_map.py index 3d41b7cc7094d..763ca9180e53a 100644 --- a/pandas/tests/arrays/categorical/test_map.py +++ b/pandas/tests/arrays/categorical/test_map.py @@ -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", [ diff --git a/pandas/tests/extension/base/methods.py b/pandas/tests/extension/base/methods.py index 88ef67605de98..a37493d44ff87 100644 --- a/pandas/tests/extension/base/methods.py +++ b/pandas/tests/extension/base/methods.py @@ -97,7 +97,6 @@ def test_apply_simple_series(self, data): result = pd.Series(data).apply(id) assert isinstance(result, pd.Series) - @pytest.mark.parametrize("na_action", [None, "ignore"]) def test_map(self, data_missing, na_action): result = data_missing.map(lambda x: x, na_action=na_action) expected = data_missing.to_numpy() diff --git a/pandas/tests/extension/test_arrow.py b/pandas/tests/extension/test_arrow.py index d4a4bc8bb8bd3..2634d40639661 100644 --- a/pandas/tests/extension/test_arrow.py +++ b/pandas/tests/extension/test_arrow.py @@ -271,7 +271,6 @@ def test_compare_scalar(self, data, comparison_op): ser = pd.Series(data) self._compare_other(ser, data, comparison_op, data[0]) - @pytest.mark.parametrize("na_action", [None, "ignore"]) def test_map(self, data_missing, na_action): if data_missing.dtype.kind in "mM": result = data_missing.map(lambda x: x, na_action=na_action) diff --git a/pandas/tests/extension/test_categorical.py b/pandas/tests/extension/test_categorical.py index 6f33b18b19c51..74a5110de2c8e 100644 --- a/pandas/tests/extension/test_categorical.py +++ b/pandas/tests/extension/test_categorical.py @@ -143,7 +143,6 @@ def test_combine_add(self, data_repeated): expected = pd.Series([a + val for a in list(orig_data1)]) tm.assert_series_equal(result, expected) - @pytest.mark.parametrize("na_action", [None, "ignore"]) def test_map(self, data, na_action): result = data.map(lambda x: x, na_action=na_action) tm.assert_extension_array_equal(result, data) diff --git a/pandas/tests/extension/test_datetime.py b/pandas/tests/extension/test_datetime.py index a60ece09dc73e..15373527c871e 100644 --- a/pandas/tests/extension/test_datetime.py +++ b/pandas/tests/extension/test_datetime.py @@ -107,7 +107,6 @@ def test_series_constructor(self, data): data = data._with_freq(None) super().test_series_constructor(data) - @pytest.mark.parametrize("na_action", [None, "ignore"]) def test_map(self, data, na_action): result = data.map(lambda x: x, na_action=na_action) tm.assert_extension_array_equal(result, data) diff --git a/pandas/tests/extension/test_masked.py b/pandas/tests/extension/test_masked.py index 3efc561d6a125..0e19c4078b471 100644 --- a/pandas/tests/extension/test_masked.py +++ b/pandas/tests/extension/test_masked.py @@ -169,7 +169,6 @@ def data_for_grouping(dtype): class TestMaskedArrays(base.ExtensionTests): - @pytest.mark.parametrize("na_action", [None, "ignore"]) def test_map(self, data_missing, na_action): result = data_missing.map(lambda x: x, na_action=na_action) if data_missing.dtype == Float32Dtype(): diff --git a/pandas/tests/extension/test_period.py b/pandas/tests/extension/test_period.py index 2d1d213322bac..4fe9c160d66af 100644 --- a/pandas/tests/extension/test_period.py +++ b/pandas/tests/extension/test_period.py @@ -109,7 +109,6 @@ def test_diff(self, data, periods): else: super().test_diff(data, periods) - @pytest.mark.parametrize("na_action", [None, "ignore"]) def test_map(self, data, na_action): result = data.map(lambda x: x, na_action=na_action) tm.assert_extension_array_equal(result, data) diff --git a/pandas/tests/extension/test_sparse.py b/pandas/tests/extension/test_sparse.py index 4c6550ff191a5..d0f55dde998b1 100644 --- a/pandas/tests/extension/test_sparse.py +++ b/pandas/tests/extension/test_sparse.py @@ -366,7 +366,6 @@ def test_map(self, func, na_action, expected): result = data.map(func, na_action=na_action) tm.assert_extension_array_equal(result, expected) - @pytest.mark.parametrize("na_action", [None, "ignore"]) def test_map_raises(self, data, na_action): # GH52096 msg = "fill value in the sparse values not supported" diff --git a/pandas/tests/frame/methods/test_map.py b/pandas/tests/frame/methods/test_map.py index 03681c3df844e..a60dcf9a02938 100644 --- a/pandas/tests/frame/methods/test_map.py +++ b/pandas/tests/frame/methods/test_map.py @@ -33,7 +33,6 @@ def test_map_float_object_conversion(val): assert result == object -@pytest.mark.parametrize("na_action", [None, "ignore"]) def test_map_keeps_dtype(na_action): # GH52219 arr = Series(["a", np.nan, "b"]) diff --git a/pandas/tests/series/methods/test_map.py b/pandas/tests/series/methods/test_map.py index 251d4063008b9..f4f72854e50d3 100644 --- a/pandas/tests/series/methods/test_map.py +++ b/pandas/tests/series/methods/test_map.py @@ -326,7 +326,6 @@ def test_map_dict_na_key(): tm.assert_series_equal(result, expected) -@pytest.mark.parametrize("na_action", [None, "ignore"]) def test_map_defaultdict_na_key(na_action): # GH 48813 s = Series([1, 2, np.nan]) @@ -336,7 +335,6 @@ def test_map_defaultdict_na_key(na_action): tm.assert_series_equal(result, expected) -@pytest.mark.parametrize("na_action", [None, "ignore"]) def test_map_defaultdict_missing_key(na_action): # GH 48813 s = Series([1, 2, np.nan]) @@ -346,7 +344,6 @@ def test_map_defaultdict_missing_key(na_action): tm.assert_series_equal(result, expected) -@pytest.mark.parametrize("na_action", [None, "ignore"]) def test_map_defaultdict_unmutated(na_action): # GH 48813 s = Series([1, 2, np.nan]) @@ -483,7 +480,6 @@ def test_map_box_period(): tm.assert_series_equal(res, exp) -@pytest.mark.parametrize("na_action", [None, "ignore"]) def test_map_categorical(na_action, using_infer_string): values = pd.Categorical(list("ABBABCD"), categories=list("DCBA"), ordered=True) s = Series(values, name="XX", index=list("abcdefg")) From 6c92811d12fc654c37628236f0ef518663db128c Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Wed, 20 Dec 2023 14:17:16 -0800 Subject: [PATCH 17/26] Use top level ascending fixture --- pandas/conftest.py | 8 ++++++++ pandas/tests/arrays/datetimes/test_reductions.py | 4 ---- pandas/tests/arrays/test_datetimes.py | 5 ----- pandas/tests/extension/base/methods.py | 3 --- pandas/tests/extension/json/test_json.py | 12 ------------ pandas/tests/extension/test_datetime.py | 6 +++--- pandas/tests/frame/methods/test_asfreq.py | 4 ---- pandas/tests/frame/methods/test_sort_index.py | 1 - pandas/tests/frame/methods/test_sort_values.py | 6 ------ pandas/tests/groupby/methods/test_rank.py | 2 -- pandas/tests/groupby/methods/test_value_counts.py | 1 - pandas/tests/indexes/datetimes/test_formats.py | 5 ----- pandas/tests/resample/test_datetime_index.py | 5 ----- pandas/tests/reshape/merge/test_merge_asof.py | 8 -------- pandas/tests/series/methods/test_rank.py | 1 - pandas/tests/series/methods/test_sort_values.py | 1 - pandas/tests/test_nanops.py | 4 ---- pandas/tests/window/test_expanding.py | 1 - pandas/tests/window/test_rolling.py | 1 - 19 files changed, 11 insertions(+), 67 deletions(-) diff --git a/pandas/conftest.py b/pandas/conftest.py index b19c3b9ded82f..a32476f161863 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -427,6 +427,14 @@ def na_action(request): 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 + + # ---------------------------------------------------------------- # Missing values & co. # ---------------------------------------------------------------- diff --git a/pandas/tests/arrays/datetimes/test_reductions.py b/pandas/tests/arrays/datetimes/test_reductions.py index 7d83fe6ffac7d..a58b0f57bf0da 100644 --- a/pandas/tests/arrays/datetimes/test_reductions.py +++ b/pandas/tests/arrays/datetimes/test_reductions.py @@ -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""" diff --git a/pandas/tests/arrays/test_datetimes.py b/pandas/tests/arrays/test_datetimes.py index db86f62a10484..675d500ca4401 100644 --- a/pandas/tests/arrays/test_datetimes.py +++ b/pandas/tests/arrays/test_datetimes.py @@ -28,11 +28,6 @@ class TestNonNano: - @pytest.fixture(params=["s", "ms", "us"]) - def unit(self, request): - """Fixture returning parametrized time units""" - return request.param - @pytest.fixture def dtype(self, unit, tz_naive_fixture): tz = tz_naive_fixture diff --git a/pandas/tests/extension/base/methods.py b/pandas/tests/extension/base/methods.py index a37493d44ff87..6de5c97cbfb5e 100644 --- a/pandas/tests/extension/base/methods.py +++ b/pandas/tests/extension/base/methods.py @@ -212,7 +212,6 @@ def test_nargsort(self, data_missing_for_sorting, na_position, expected): result = nargsort(data_missing_for_sorting, na_position=na_position) tm.assert_numpy_array_equal(result, expected) - @pytest.mark.parametrize("ascending", [True, False]) def test_sort_values(self, data_for_sorting, ascending, sort_by_key): ser = pd.Series(data_for_sorting) result = ser.sort_values(ascending=ascending, key=sort_by_key) @@ -226,7 +225,6 @@ def test_sort_values(self, data_for_sorting, ascending, sort_by_key): tm.assert_series_equal(result, expected) - @pytest.mark.parametrize("ascending", [True, False]) def test_sort_values_missing( self, data_missing_for_sorting, ascending, sort_by_key ): @@ -238,7 +236,6 @@ def test_sort_values_missing( expected = ser.iloc[[0, 2, 1]] tm.assert_series_equal(result, expected) - @pytest.mark.parametrize("ascending", [True, False]) def test_sort_values_frame(self, data_for_sorting, ascending): df = pd.DataFrame({"A": [1, 2, 1], "B": data_for_sorting}) result = df.sort_values(["A", "B"]) diff --git a/pandas/tests/extension/json/test_json.py b/pandas/tests/extension/json/test_json.py index 7686bc5abb44c..5319291f2ea01 100644 --- a/pandas/tests/extension/json/test_json.py +++ b/pandas/tests/extension/json/test_json.py @@ -162,18 +162,6 @@ def test_sort_values_frame(self): # TODO (EA.factorize): see if _values_for_factorize allows this. super().test_sort_values_frame() - @pytest.mark.parametrize("ascending", [True, False]) - def test_sort_values(self, data_for_sorting, ascending, sort_by_key): - super().test_sort_values(data_for_sorting, ascending, sort_by_key) - - @pytest.mark.parametrize("ascending", [True, False]) - def test_sort_values_missing( - self, data_missing_for_sorting, ascending, sort_by_key - ): - super().test_sort_values_missing( - data_missing_for_sorting, ascending, sort_by_key - ) - @pytest.mark.xfail(reason="combine for JSONArray not supported") def test_combine_le(self, data_repeated): super().test_combine_le(data_repeated) diff --git a/pandas/tests/extension/test_datetime.py b/pandas/tests/extension/test_datetime.py index 15373527c871e..c5f6b0e16328c 100644 --- a/pandas/tests/extension/test_datetime.py +++ b/pandas/tests/extension/test_datetime.py @@ -24,9 +24,9 @@ from pandas.tests.extension import base -@pytest.fixture(params=["US/Central"]) -def dtype(request): - return DatetimeTZDtype(unit="ns", tz=request.param) +@pytest.fixture +def dtype(): + return DatetimeTZDtype(unit="ns", tz="US/Central") @pytest.fixture diff --git a/pandas/tests/frame/methods/test_asfreq.py b/pandas/tests/frame/methods/test_asfreq.py index ef72ca1ac86b9..87d1745774487 100644 --- a/pandas/tests/frame/methods/test_asfreq.py +++ b/pandas/tests/frame/methods/test_asfreq.py @@ -19,10 +19,6 @@ class TestAsFreq: - @pytest.fixture(params=["s", "ms", "us", "ns"]) - def unit(self, request): - return request.param - def test_asfreq2(self, frame_or_series): ts = frame_or_series( [0.0, 1.0, 2.0], diff --git a/pandas/tests/frame/methods/test_sort_index.py b/pandas/tests/frame/methods/test_sort_index.py index 49e292057e4dc..821b2e0d7a6da 100644 --- a/pandas/tests/frame/methods/test_sort_index.py +++ b/pandas/tests/frame/methods/test_sort_index.py @@ -927,7 +927,6 @@ def test_sort_index_na_position(self): result = df.sort_index(level=[0, 1], na_position="last") tm.assert_frame_equal(result, expected) - @pytest.mark.parametrize("ascending", [True, False]) def test_sort_index_multiindex_sort_remaining(self, ascending): # GH #24247 df = DataFrame( diff --git a/pandas/tests/frame/methods/test_sort_values.py b/pandas/tests/frame/methods/test_sort_values.py index f2f02058a534e..33adfcbc6f5ee 100644 --- a/pandas/tests/frame/methods/test_sort_values.py +++ b/pandas/tests/frame/methods/test_sort_values.py @@ -849,11 +849,6 @@ def sort_names(request): return request.param -@pytest.fixture(params=[True, False]) -def ascending(request): - return request.param - - class TestSortValuesLevelAsStr: def test_sort_index_level_and_column_label( self, df_none, df_idx, sort_names, ascending, request @@ -927,7 +922,6 @@ def test_sort_values_validate_ascending_for_value_error(self): with pytest.raises(ValueError, match=msg): df.sort_values(by="D", ascending="False") - @pytest.mark.parametrize("ascending", [False, 0, 1, True]) def test_sort_values_validate_ascending_functional(self, ascending): df = DataFrame({"D": [23, 7, 21]}) indexer = df["D"].argsort().values diff --git a/pandas/tests/groupby/methods/test_rank.py b/pandas/tests/groupby/methods/test_rank.py index a3b7da3fa836c..035fbbbdd3685 100644 --- a/pandas/tests/groupby/methods/test_rank.py +++ b/pandas/tests/groupby/methods/test_rank.py @@ -481,7 +481,6 @@ def test_rank_avg_even_vals(dtype, upper): @pytest.mark.parametrize("ties_method", ["average", "min", "max", "first", "dense"]) -@pytest.mark.parametrize("ascending", [True, False]) @pytest.mark.parametrize("na_option", ["keep", "top", "bottom"]) @pytest.mark.parametrize("pct", [True, False]) @pytest.mark.parametrize( @@ -510,7 +509,6 @@ def test_rank_object_dtype(ties_method, ascending, na_option, pct, vals): @pytest.mark.parametrize("na_option", [True, "bad", 1]) @pytest.mark.parametrize("ties_method", ["average", "min", "max", "first", "dense"]) -@pytest.mark.parametrize("ascending", [True, False]) @pytest.mark.parametrize("pct", [True, False]) @pytest.mark.parametrize( "vals", diff --git a/pandas/tests/groupby/methods/test_value_counts.py b/pandas/tests/groupby/methods/test_value_counts.py index 538ed7f93f857..33da9cd965809 100644 --- a/pandas/tests/groupby/methods/test_value_counts.py +++ b/pandas/tests/groupby/methods/test_value_counts.py @@ -76,7 +76,6 @@ def seed_df(seed_nans, n, m): @pytest.mark.parametrize("bins", [None, [0, 5]], ids=repr) @pytest.mark.parametrize("isort", [True, False]) @pytest.mark.parametrize("normalize, name", [(True, "proportion"), (False, "count")]) -@pytest.mark.parametrize("ascending", [True, False]) def test_series_groupby_value_counts( seed_nans, num_rows, diff --git a/pandas/tests/indexes/datetimes/test_formats.py b/pandas/tests/indexes/datetimes/test_formats.py index b52eed8c509c6..f8b01f7985535 100644 --- a/pandas/tests/indexes/datetimes/test_formats.py +++ b/pandas/tests/indexes/datetimes/test_formats.py @@ -14,11 +14,6 @@ import pandas._testing as tm -@pytest.fixture(params=["s", "ms", "us", "ns"]) -def unit(request): - return request.param - - def test_get_values_for_csv(): index = pd.date_range(freq="1D", periods=3, start="2017-01-01") diff --git a/pandas/tests/resample/test_datetime_index.py b/pandas/tests/resample/test_datetime_index.py index 80583f5d3c5f2..18629d1c5f2a5 100644 --- a/pandas/tests/resample/test_datetime_index.py +++ b/pandas/tests/resample/test_datetime_index.py @@ -51,11 +51,6 @@ def _static_values(index): return np.random.default_rng(2).random(len(index)) -@pytest.fixture(params=["s", "ms", "us", "ns"]) -def unit(request): - return request.param - - @pytest.fixture def simple_date_range_series(): """ diff --git a/pandas/tests/reshape/merge/test_merge_asof.py b/pandas/tests/reshape/merge/test_merge_asof.py index b656191cc739d..33502f576dd2f 100644 --- a/pandas/tests/reshape/merge/test_merge_asof.py +++ b/pandas/tests/reshape/merge/test_merge_asof.py @@ -18,14 +18,6 @@ from pandas.core.reshape.merge import MergeError -@pytest.fixture(params=["s", "ms", "us", "ns"]) -def unit(request): - """ - Resolution for datetimelike dtypes. - """ - return request.param - - class TestAsOfMerge: def prep_data(self, df, dedupe=False): if dedupe: diff --git a/pandas/tests/series/methods/test_rank.py b/pandas/tests/series/methods/test_rank.py index 24cf97c05c0a8..8a97c34318e71 100644 --- a/pandas/tests/series/methods/test_rank.py +++ b/pandas/tests/series/methods/test_rank.py @@ -248,7 +248,6 @@ def test_rank_tie_methods(self, ser, results, dtype): result = ser.rank(method=method) tm.assert_series_equal(result, Series(exp)) - @pytest.mark.parametrize("ascending", [True, False]) @pytest.mark.parametrize("method", ["average", "min", "max", "first", "dense"]) @pytest.mark.parametrize("na_option", ["top", "bottom", "keep"]) @pytest.mark.parametrize( diff --git a/pandas/tests/series/methods/test_sort_values.py b/pandas/tests/series/methods/test_sort_values.py index 4808272879071..00142c4d82327 100644 --- a/pandas/tests/series/methods/test_sort_values.py +++ b/pandas/tests/series/methods/test_sort_values.py @@ -204,7 +204,6 @@ def test_sort_values_validate_ascending_for_value_error(self): with pytest.raises(ValueError, match=msg): ser.sort_values(ascending="False") - @pytest.mark.parametrize("ascending", [False, 0, 1, True]) def test_sort_values_validate_ascending_functional(self, ascending): # GH41634 ser = Series([23, 7, 21]) diff --git a/pandas/tests/test_nanops.py b/pandas/tests/test_nanops.py index 632d9783c7f81..6eac4822585dc 100644 --- a/pandas/tests/test_nanops.py +++ b/pandas/tests/test_nanops.py @@ -1103,10 +1103,6 @@ def prng(self): class TestDatetime64NaNOps: - @pytest.fixture(params=["s", "ms", "us", "ns"]) - def unit(self, request): - return request.param - # Enabling mean changes the behavior of DataFrame.mean # See https://github.com/pandas-dev/pandas/issues/24752 def test_nanmean(self, unit): diff --git a/pandas/tests/window/test_expanding.py b/pandas/tests/window/test_expanding.py index e56d62e98d258..10d0afb5a2412 100644 --- a/pandas/tests/window/test_expanding.py +++ b/pandas/tests/window/test_expanding.py @@ -241,7 +241,6 @@ def test_expanding_skew_kurt_numerical_stability(method): @pytest.mark.parametrize("window", [1, 3, 10, 20]) @pytest.mark.parametrize("method", ["min", "max", "average"]) @pytest.mark.parametrize("pct", [True, False]) -@pytest.mark.parametrize("ascending", [True, False]) @pytest.mark.parametrize("test_data", ["default", "duplicates", "nans"]) def test_rank(window, method, pct, ascending, test_data): length = 20 diff --git a/pandas/tests/window/test_rolling.py b/pandas/tests/window/test_rolling.py index e1362109c8157..a9a4a2a2bd991 100644 --- a/pandas/tests/window/test_rolling.py +++ b/pandas/tests/window/test_rolling.py @@ -1629,7 +1629,6 @@ def test_rolling_numeric_dtypes(): @pytest.mark.parametrize("window", [1, 3, 10, 20]) @pytest.mark.parametrize("method", ["min", "max", "average"]) @pytest.mark.parametrize("pct", [True, False]) -@pytest.mark.parametrize("ascending", [True, False]) @pytest.mark.parametrize("test_data", ["default", "duplicates", "nans"]) def test_rank(window, method, pct, ascending, test_data): length = 20 From 3124ac508d40645ba786610a3f2121cb4c9918a1 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Wed, 20 Dec 2023 14:26:21 -0800 Subject: [PATCH 18/26] Use shared rank_method fixture --- pandas/conftest.py | 8 +++++ pandas/tests/frame/methods/test_rank.py | 41 ++++++++++------------- pandas/tests/groupby/methods/test_rank.py | 12 +++---- pandas/tests/series/methods/test_rank.py | 20 ++++++----- 4 files changed, 42 insertions(+), 39 deletions(-) diff --git a/pandas/conftest.py b/pandas/conftest.py index a32476f161863..dbfc0e9cab9bc 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -435,6 +435,14 @@ def ascending(request): return request.param +@pytest.fixture(params=["average", "min", "max", "first", "dense"]) +def rank_method(request): + """ + Fixture for 'rank' argument in rank. + """ + return request.param + + # ---------------------------------------------------------------- # Missing values & co. # ---------------------------------------------------------------- diff --git a/pandas/tests/frame/methods/test_rank.py b/pandas/tests/frame/methods/test_rank.py index 8d7a0b373f5f8..1d0931f5982b7 100644 --- a/pandas/tests/frame/methods/test_rank.py +++ b/pandas/tests/frame/methods/test_rank.py @@ -31,13 +31,6 @@ class TestRank: "dense": np.array([1, 3, 4, 2, np.nan, 2, 1, 5, np.nan, 3]), } - @pytest.fixture(params=["average", "min", "max", "first", "dense"]) - def method(self, request): - """ - Fixture for trying all rank methods - """ - return request.param - def test_rank(self, float_frame): sp_stats = pytest.importorskip("scipy.stats") @@ -225,8 +218,7 @@ def test_rank_axis(self): tm.assert_frame_equal(df.rank(axis=1), df.rank(axis="columns")) @pytest.mark.parametrize("ax", [0, 1]) - @pytest.mark.parametrize("m", ["average", "min", "max", "first", "dense"]) - def test_rank_methods_frame(self, ax, m): + def test_rank_methods_frame(self, ax, rank_method): sp_stats = pytest.importorskip("scipy.stats") xs = np.random.default_rng(2).integers(0, 21, (100, 26)) @@ -236,16 +228,19 @@ def test_rank_methods_frame(self, ax, m): for vals in [xs, xs + 1e6, xs * 1e-6]: df = DataFrame(vals, columns=cols) - result = df.rank(axis=ax, method=m) + result = df.rank(axis=ax, method=rank_method) sprank = np.apply_along_axis( - sp_stats.rankdata, ax, vals, m if m != "first" else "ordinal" + sp_stats.rankdata, + ax, + vals, + rank_method if rank_method != "first" else "ordinal", ) sprank = sprank.astype(np.float64) expected = DataFrame(sprank, columns=cols).astype("float64") tm.assert_frame_equal(result, expected) @pytest.mark.parametrize("dtype", ["O", "f8", "i8"]) - def test_rank_descending(self, method, dtype): + def test_rank_descending(self, rank_method, dtype): if "i" in dtype: df = self.df.dropna().astype(dtype) else: @@ -255,18 +250,18 @@ def test_rank_descending(self, method, dtype): expected = (df.max() - df).rank() tm.assert_frame_equal(res, expected) - expected = (df.max() - df).rank(method=method) + expected = (df.max() - df).rank(method=rank_method) if dtype != "O": - res2 = df.rank(method=method, ascending=False, numeric_only=True) + res2 = df.rank(method=rank_method, ascending=False, numeric_only=True) tm.assert_frame_equal(res2, expected) - res3 = df.rank(method=method, ascending=False, numeric_only=False) + res3 = df.rank(method=rank_method, ascending=False, numeric_only=False) tm.assert_frame_equal(res3, expected) @pytest.mark.parametrize("axis", [0, 1]) @pytest.mark.parametrize("dtype", [None, object]) - def test_rank_2d_tie_methods(self, method, axis, dtype): + def test_rank_2d_tie_methods(self, rank_method, axis, dtype): df = self.df def _check2d(df, expected, method="average", axis=0): @@ -276,14 +271,14 @@ def _check2d(df, expected, method="average", axis=0): df = df.T exp_df = exp_df.T - result = df.rank(method=method, axis=axis) + result = df.rank(method=rank_method, axis=axis) tm.assert_frame_equal(result, exp_df) frame = df if dtype is None else df.astype(dtype) - _check2d(frame, self.results[method], method=method, axis=axis) + _check2d(frame, self.results[rank_method], method=rank_method, axis=axis) @pytest.mark.parametrize( - "method,exp", + "rank_method,exp", [ ("dense", [[1.0, 1.0, 1.0], [1.0, 0.5, 2.0 / 3], [1.0, 0.5, 1.0 / 3]]), ( @@ -312,11 +307,11 @@ def _check2d(df, expected, method="average", axis=0): ), ], ) - def test_rank_pct_true(self, method, exp): + def test_rank_pct_true(self, rank_method, exp): # see gh-15630. df = DataFrame([[2012, 66, 3], [2012, 65, 2], [2012, 65, 1]]) - result = df.rank(method=method, pct=True) + result = df.rank(method=rank_method, pct=True) expected = DataFrame(exp) tm.assert_frame_equal(result, expected) @@ -454,10 +449,10 @@ def test_rank_both_inf(self): ], ) def test_rank_inf_nans_na_option( - self, frame_or_series, method, na_option, ascending, expected + self, frame_or_series, rank_method, na_option, ascending, expected ): obj = frame_or_series([np.inf, np.nan, -np.inf]) - result = obj.rank(method=method, na_option=na_option, ascending=ascending) + result = obj.rank(method=rank_method, na_option=na_option, ascending=ascending) expected = frame_or_series(expected) tm.assert_equal(result, expected) diff --git a/pandas/tests/groupby/methods/test_rank.py b/pandas/tests/groupby/methods/test_rank.py index 035fbbbdd3685..18869033d05c6 100644 --- a/pandas/tests/groupby/methods/test_rank.py +++ b/pandas/tests/groupby/methods/test_rank.py @@ -480,18 +480,17 @@ def test_rank_avg_even_vals(dtype, upper): tm.assert_frame_equal(result, exp_df) -@pytest.mark.parametrize("ties_method", ["average", "min", "max", "first", "dense"]) @pytest.mark.parametrize("na_option", ["keep", "top", "bottom"]) @pytest.mark.parametrize("pct", [True, False]) @pytest.mark.parametrize( "vals", [["bar", "bar", "foo", "bar", "baz"], ["bar", np.nan, "foo", np.nan, "baz"]] ) -def test_rank_object_dtype(ties_method, ascending, na_option, pct, vals): +def test_rank_object_dtype(rank_method, ascending, na_option, pct, vals): df = DataFrame({"key": ["foo"] * 5, "val": vals}) mask = df["val"].isna() gb = df.groupby("key") - res = gb.rank(method=ties_method, ascending=ascending, na_option=na_option, pct=pct) + res = gb.rank(method=rank_method, ascending=ascending, na_option=na_option, pct=pct) # construct our expected by using numeric values with the same ordering if mask.any(): @@ -501,14 +500,13 @@ def test_rank_object_dtype(ties_method, ascending, na_option, pct, vals): gb2 = df2.groupby("key") alt = gb2.rank( - method=ties_method, ascending=ascending, na_option=na_option, pct=pct + method=rank_method, ascending=ascending, na_option=na_option, pct=pct ) tm.assert_frame_equal(res, alt) @pytest.mark.parametrize("na_option", [True, "bad", 1]) -@pytest.mark.parametrize("ties_method", ["average", "min", "max", "first", "dense"]) @pytest.mark.parametrize("pct", [True, False]) @pytest.mark.parametrize( "vals", @@ -518,13 +516,13 @@ def test_rank_object_dtype(ties_method, ascending, na_option, pct, vals): [1, np.nan, 2, np.nan, 3], ], ) -def test_rank_naoption_raises(ties_method, ascending, na_option, pct, vals): +def test_rank_naoption_raises(rank_method, ascending, na_option, pct, vals): df = DataFrame({"key": ["foo"] * 5, "val": vals}) msg = "na_option must be one of 'keep', 'top', or 'bottom'" with pytest.raises(ValueError, match=msg): df.groupby("key").rank( - method=ties_method, ascending=ascending, na_option=na_option, pct=pct + method=rank_method, ascending=ascending, na_option=na_option, pct=pct ) diff --git a/pandas/tests/series/methods/test_rank.py b/pandas/tests/series/methods/test_rank.py index 8a97c34318e71..4d48f290e6a44 100644 --- a/pandas/tests/series/methods/test_rank.py +++ b/pandas/tests/series/methods/test_rank.py @@ -248,7 +248,6 @@ def test_rank_tie_methods(self, ser, results, dtype): result = ser.rank(method=method) tm.assert_series_equal(result, Series(exp)) - @pytest.mark.parametrize("method", ["average", "min", "max", "first", "dense"]) @pytest.mark.parametrize("na_option", ["top", "bottom", "keep"]) @pytest.mark.parametrize( "dtype, na_value, pos_inf, neg_inf", @@ -266,11 +265,11 @@ def test_rank_tie_methods(self, ser, results, dtype): ], ) def test_rank_tie_methods_on_infs_nans( - self, method, na_option, ascending, dtype, na_value, pos_inf, neg_inf + self, rank_method, na_option, ascending, dtype, na_value, pos_inf, neg_inf ): pytest.importorskip("scipy") if dtype == "float64[pyarrow]": - if method == "average": + if rank_method == "average": exp_dtype = "float64[pyarrow]" else: exp_dtype = "uint64[pyarrow]" @@ -287,7 +286,7 @@ def test_rank_tie_methods_on_infs_nans( "first": ([1, 2, 3], [4, 5, 6], [7, 8, 9]), "dense": ([1, 1, 1], [2, 2, 2], [3, 3, 3]), } - ranks = exp_ranks[method] + ranks = exp_ranks[rank_method] if na_option == "top": order = [ranks[1], ranks[0], ranks[2]] elif na_option == "bottom": @@ -296,7 +295,9 @@ def test_rank_tie_methods_on_infs_nans( order = [ranks[0], [np.nan] * chunk, ranks[1]] expected = order if ascending else order[::-1] expected = list(chain.from_iterable(expected)) - result = iseries.rank(method=method, na_option=na_option, ascending=ascending) + result = iseries.rank( + method=rank_method, na_option=na_option, ascending=ascending + ) tm.assert_series_equal(result, Series(expected, dtype=exp_dtype)) def test_rank_desc_mix_nans_infs(self): @@ -307,7 +308,6 @@ def test_rank_desc_mix_nans_infs(self): exp = Series([3, np.nan, 1, 4, 2], dtype="float64") tm.assert_series_equal(result, exp) - @pytest.mark.parametrize("method", ["average", "min", "max", "first", "dense"]) @pytest.mark.parametrize( "op, value", [ @@ -316,7 +316,7 @@ def test_rank_desc_mix_nans_infs(self): [operator.mul, 1e-6], ], ) - def test_rank_methods_series(self, method, op, value): + def test_rank_methods_series(self, rank_method, op, value): sp_stats = pytest.importorskip("scipy.stats") xs = np.random.default_rng(2).standard_normal(9) @@ -326,8 +326,10 @@ def test_rank_methods_series(self, method, op, value): index = [chr(ord("a") + i) for i in range(len(xs))] vals = op(xs, value) ts = Series(vals, index=index) - result = ts.rank(method=method) - sprank = sp_stats.rankdata(vals, method if method != "first" else "ordinal") + result = ts.rank(method=rank_method) + sprank = sp_stats.rankdata( + vals, rank_method if rank_method != "first" else "ordinal" + ) expected = Series(sprank, index=index).astype("float64") tm.assert_series_equal(result, expected) From db80a7de9bda4c16ee9d8e48a76de0f24085c498 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Wed, 20 Dec 2023 14:30:26 -0800 Subject: [PATCH 19/26] Use shared as_index fixture --- pandas/conftest.py | 8 ++++++++ pandas/tests/extension/base/groupby.py | 1 - pandas/tests/extension/test_categorical.py | 1 - pandas/tests/extension/test_sparse.py | 1 - pandas/tests/groupby/aggregate/test_numba.py | 1 - pandas/tests/groupby/conftest.py | 5 ----- pandas/tests/groupby/methods/test_describe.py | 1 - pandas/tests/groupby/methods/test_nth.py | 1 - pandas/tests/groupby/methods/test_size.py | 1 - pandas/tests/groupby/methods/test_value_counts.py | 7 ------- pandas/tests/groupby/test_groupby.py | 1 - pandas/tests/groupby/test_reductions.py | 1 - pandas/tests/groupby/transform/test_numba.py | 1 - 13 files changed, 8 insertions(+), 22 deletions(-) diff --git a/pandas/conftest.py b/pandas/conftest.py index dbfc0e9cab9bc..c9339739774f1 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -443,6 +443,14 @@ def rank_method(request): return request.param +@pytest.fixture(params=[True, False]) +def as_index(request): + """ + Fixture for 'as_index' argument in groupby. + """ + return request.param + + # ---------------------------------------------------------------- # Missing values & co. # ---------------------------------------------------------------- diff --git a/pandas/tests/extension/base/groupby.py b/pandas/tests/extension/base/groupby.py index 75628ea177fc2..9f38246d1a317 100644 --- a/pandas/tests/extension/base/groupby.py +++ b/pandas/tests/extension/base/groupby.py @@ -34,7 +34,6 @@ def test_grouping_grouper(self, data_for_grouping): tm.assert_numpy_array_equal(gr1.grouping_vector, df.A.values) tm.assert_extension_array_equal(gr2.grouping_vector, data_for_grouping) - @pytest.mark.parametrize("as_index", [True, False]) def test_groupby_extension_agg(self, as_index, data_for_grouping): df = pd.DataFrame({"A": [1, 1, 2, 2, 3, 3, 1, 4], "B": data_for_grouping}) diff --git a/pandas/tests/extension/test_categorical.py b/pandas/tests/extension/test_categorical.py index 74a5110de2c8e..7598aca10bad4 100644 --- a/pandas/tests/extension/test_categorical.py +++ b/pandas/tests/extension/test_categorical.py @@ -183,7 +183,6 @@ def test_array_repr(self, data, size): super().test_array_repr(data, size) @pytest.mark.xfail(reason="TBD") - @pytest.mark.parametrize("as_index", [True, False]) def test_groupby_extension_agg(self, as_index, data_for_grouping): super().test_groupby_extension_agg(as_index, data_for_grouping) diff --git a/pandas/tests/extension/test_sparse.py b/pandas/tests/extension/test_sparse.py index d0f55dde998b1..03f179fdd261e 100644 --- a/pandas/tests/extension/test_sparse.py +++ b/pandas/tests/extension/test_sparse.py @@ -486,7 +486,6 @@ def test_array_repr(self, data, size): super().test_array_repr(data, size) @pytest.mark.xfail(reason="result does not match expected") - @pytest.mark.parametrize("as_index", [True, False]) def test_groupby_extension_agg(self, as_index, data_for_grouping): super().test_groupby_extension_agg(as_index, data_for_grouping) diff --git a/pandas/tests/groupby/aggregate/test_numba.py b/pandas/tests/groupby/aggregate/test_numba.py index ee694129f7118..89404a9bd09a3 100644 --- a/pandas/tests/groupby/aggregate/test_numba.py +++ b/pandas/tests/groupby/aggregate/test_numba.py @@ -53,7 +53,6 @@ def incorrect_function(values, index): # Filter warnings when parallel=True and the function can't be parallelized by Numba @pytest.mark.parametrize("jit", [True, False]) @pytest.mark.parametrize("pandas_obj", ["Series", "DataFrame"]) -@pytest.mark.parametrize("as_index", [True, False]) def test_numba_vs_cython(jit, pandas_obj, nogil, parallel, nopython, as_index): pytest.importorskip("numba") diff --git a/pandas/tests/groupby/conftest.py b/pandas/tests/groupby/conftest.py index 187076a7bac0d..1f1401b8dcce3 100644 --- a/pandas/tests/groupby/conftest.py +++ b/pandas/tests/groupby/conftest.py @@ -13,11 +13,6 @@ ) -@pytest.fixture(params=[True, False]) -def as_index(request): - return request.param - - @pytest.fixture def df(): return DataFrame( diff --git a/pandas/tests/groupby/methods/test_describe.py b/pandas/tests/groupby/methods/test_describe.py index a2440e09dfc02..f27e99809176c 100644 --- a/pandas/tests/groupby/methods/test_describe.py +++ b/pandas/tests/groupby/methods/test_describe.py @@ -149,7 +149,6 @@ def test_frame_describe_unstacked_format(): "indexing past lexsort depth may impact performance:" "pandas.errors.PerformanceWarning" ) -@pytest.mark.parametrize("as_index", [True, False]) @pytest.mark.parametrize("keys", [["a1"], ["a1", "a2"]]) def test_describe_with_duplicate_output_column_names(as_index, keys): # GH 35314 diff --git a/pandas/tests/groupby/methods/test_nth.py b/pandas/tests/groupby/methods/test_nth.py index a8ed9e9d52021..52d63cb720485 100644 --- a/pandas/tests/groupby/methods/test_nth.py +++ b/pandas/tests/groupby/methods/test_nth.py @@ -529,7 +529,6 @@ def test_nth_multi_index_as_expected(): ], ) @pytest.mark.parametrize("columns", [None, [], ["A"], ["B"], ["A", "B"]]) -@pytest.mark.parametrize("as_index", [True, False]) def test_groupby_head_tail(op, n, expected_rows, columns, as_index): df = DataFrame([[1, 2], [1, 4], [5, 6]], columns=["A", "B"]) g = df.groupby("A", as_index=as_index) diff --git a/pandas/tests/groupby/methods/test_size.py b/pandas/tests/groupby/methods/test_size.py index 92a277d8014d4..fd55ceedd1083 100644 --- a/pandas/tests/groupby/methods/test_size.py +++ b/pandas/tests/groupby/methods/test_size.py @@ -83,7 +83,6 @@ def test_size_period_index(): tm.assert_series_equal(result, ser) -@pytest.mark.parametrize("as_index", [True, False]) def test_size_on_categorical(as_index): df = DataFrame([[1, 1], [2, 2]], columns=["A", "B"]) df["A"] = df["A"].astype("category") diff --git a/pandas/tests/groupby/methods/test_value_counts.py b/pandas/tests/groupby/methods/test_value_counts.py index 33da9cd965809..5c9f7febe32b3 100644 --- a/pandas/tests/groupby/methods/test_value_counts.py +++ b/pandas/tests/groupby/methods/test_value_counts.py @@ -292,7 +292,6 @@ def _frame_value_counts(df, keys, normalize, sort, ascending): (True, False), ], ) -@pytest.mark.parametrize("as_index", [True, False]) @pytest.mark.parametrize("frame", [True, False]) def test_against_frame_and_seriesgroupby( education_df, groupby, normalize, name, sort, ascending, as_index, frame, request @@ -580,7 +579,6 @@ def test_data_frame_value_counts_dropna( tm.assert_series_equal(result_frame_groupby, expected) -@pytest.mark.parametrize("as_index", [False, True]) @pytest.mark.parametrize("observed", [False, True]) @pytest.mark.parametrize( "normalize, name, expected_data", @@ -690,7 +688,6 @@ def assert_categorical_single_grouper( tm.assert_frame_equal(result, expected) -@pytest.mark.parametrize("as_index", [True, False]) @pytest.mark.parametrize( "normalize, name, expected_data", [ @@ -748,7 +745,6 @@ def test_categorical_single_grouper_observed_true( ) -@pytest.mark.parametrize("as_index", [True, False]) @pytest.mark.parametrize( "normalize, name, expected_data", [ @@ -835,7 +831,6 @@ def test_categorical_single_grouper_observed_false( ) -@pytest.mark.parametrize("as_index", [True, False]) @pytest.mark.parametrize( "observed, expected_index", [ @@ -921,7 +916,6 @@ def test_categorical_multiple_groupers( tm.assert_frame_equal(result, expected) -@pytest.mark.parametrize("as_index", [False, True]) @pytest.mark.parametrize("observed", [False, True]) @pytest.mark.parametrize( "normalize, name, expected_data", @@ -1030,7 +1024,6 @@ def test_mixed_groupings(normalize, expected_label, expected_values): ("level", list("abcd") + ["level_1"], ["a", None, "d", "b", "c", "level_1"]), ], ) -@pytest.mark.parametrize("as_index", [False, True]) def test_column_label_duplicates(test, columns, expected_names, as_index): # GH 44992 # Test for duplicate input column labels and generated duplicate labels diff --git a/pandas/tests/groupby/test_groupby.py b/pandas/tests/groupby/test_groupby.py index fce7caa90cce4..2ac1f4faa998e 100644 --- a/pandas/tests/groupby/test_groupby.py +++ b/pandas/tests/groupby/test_groupby.py @@ -295,7 +295,6 @@ def f(x, q=None, axis=0): tm.assert_frame_equal(apply_result, expected, check_names=False) -@pytest.mark.parametrize("as_index", [True, False]) def test_pass_args_kwargs_duplicate_columns(tsframe, as_index): # go through _aggregate_frame with self.axis == 0 and duplicate columns tsframe.columns = ["A", "B", "A", "C"] diff --git a/pandas/tests/groupby/test_reductions.py b/pandas/tests/groupby/test_reductions.py index ba73bf3b9908a..bb5ea233c27be 100644 --- a/pandas/tests/groupby/test_reductions.py +++ b/pandas/tests/groupby/test_reductions.py @@ -635,7 +635,6 @@ def test_max_nan_bug(): @pytest.mark.slow -@pytest.mark.parametrize("as_index", [True, False]) @pytest.mark.parametrize("with_nan", [True, False]) @pytest.mark.parametrize("keys", [["joe"], ["joe", "jim"]]) def test_series_groupby_nunique(sort, dropna, as_index, with_nan, keys): diff --git a/pandas/tests/groupby/transform/test_numba.py b/pandas/tests/groupby/transform/test_numba.py index 61fcc930f116a..af11dae0aabfe 100644 --- a/pandas/tests/groupby/transform/test_numba.py +++ b/pandas/tests/groupby/transform/test_numba.py @@ -51,7 +51,6 @@ def incorrect_function(values, index): # Filter warnings when parallel=True and the function can't be parallelized by Numba @pytest.mark.parametrize("jit", [True, False]) @pytest.mark.parametrize("pandas_obj", ["Series", "DataFrame"]) -@pytest.mark.parametrize("as_index", [True, False]) def test_numba_vs_cython(jit, pandas_obj, nogil, parallel, nopython, as_index): pytest.importorskip("numba") From 839f5ad8562084cd4b372ad9fc656a9c8b4047be Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Wed, 20 Dec 2023 14:41:44 -0800 Subject: [PATCH 20/26] Share more fixtures --- pandas/tests/indexes/numeric/test_numeric.py | 6 +++--- pandas/tests/indexing/test_loc.py | 6 +++--- pandas/tests/io/excel/test_xlrd.py | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pandas/tests/indexes/numeric/test_numeric.py b/pandas/tests/indexes/numeric/test_numeric.py index 7ce55db6c0bbc..1a2fefc33f157 100644 --- a/pandas/tests/indexes/numeric/test_numeric.py +++ b/pandas/tests/indexes/numeric/test_numeric.py @@ -237,9 +237,9 @@ def test_logical_compat(self, simple_index): class TestNumericInt: - @pytest.fixture(params=[np.int64, np.int32, np.int16, np.int8, np.uint64]) - def dtype(self, request): - return request.param + @pytest.fixture + def dtype(self, any_int_numpy_dtype): + return np.dtype(any_int_numpy_dtype) @pytest.fixture def simple_index(self, dtype): diff --git a/pandas/tests/indexing/test_loc.py b/pandas/tests/indexing/test_loc.py index ce7dde3c4cb42..b9e28e8e0fcac 100644 --- a/pandas/tests/indexing/test_loc.py +++ b/pandas/tests/indexing/test_loc.py @@ -1687,10 +1687,10 @@ def test_loc_setitem_numpy_frame_categorical_value(self): class TestLocWithEllipsis: - @pytest.fixture(params=[tm.loc, tm.iloc]) - def indexer(self, request): + @pytest.fixture + def indexer(self, indexer_li): # Test iloc while we're here - return request.param + return indexer_li @pytest.fixture def obj(self, series_with_simple_index, frame_or_series): diff --git a/pandas/tests/io/excel/test_xlrd.py b/pandas/tests/io/excel/test_xlrd.py index 6d5008ca9ee68..c49cbaf7fb26c 100644 --- a/pandas/tests/io/excel/test_xlrd.py +++ b/pandas/tests/io/excel/test_xlrd.py @@ -12,14 +12,14 @@ xlrd = pytest.importorskip("xlrd") -@pytest.fixture(params=[".xls"]) -def read_ext_xlrd(request): +@pytest.fixture +def read_ext_xlrd(): """ Valid extensions for reading Excel files with xlrd. Similar to read_ext, but excludes .ods, .xlsb, and for xlrd>2 .xlsx, .xlsm """ - return request.param + return ".xls" def test_read_xlrd_book(read_ext_xlrd, datapath): From fa876fb108c0cb39423074c5f4d5708d2d14fdbc Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Wed, 20 Dec 2023 14:45:03 -0800 Subject: [PATCH 21/26] Reuse orient fixture --- pandas/tests/io/json/test_pandas.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/pandas/tests/io/json/test_pandas.py b/pandas/tests/io/json/test_pandas.py index 58a1e51d31b74..9d608165ede6c 100644 --- a/pandas/tests/io/json/test_pandas.py +++ b/pandas/tests/io/json/test_pandas.py @@ -2026,9 +2026,6 @@ def test_json_uint64(self): result = df.to_json(orient="split") assert result == expected - @pytest.mark.parametrize( - "orient", ["split", "records", "values", "index", "columns"] - ) def test_read_json_dtype_backend( self, string_storage, dtype_backend, orient, using_infer_string ): From c31b95f6e7111badc453e6496aa4e8ad1772679d Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Wed, 20 Dec 2023 14:51:26 -0800 Subject: [PATCH 22/26] Use shared cache fixture --- pandas/conftest.py | 8 ++++++++ pandas/tests/io/parser/test_parse_dates.py | 12 +++++------- pandas/tests/tools/test_to_datetime.py | 10 ---------- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/pandas/conftest.py b/pandas/conftest.py index c9339739774f1..44bb3360e824e 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -451,6 +451,14 @@ def as_index(request): return request.param +@pytest.fixture(params=[True, False]) +def cache(request): + """ + Fixture for 'cache' argument in to_datetime. + """ + return request.param + + # ---------------------------------------------------------------- # Missing values & co. # ---------------------------------------------------------------- diff --git a/pandas/tests/io/parser/test_parse_dates.py b/pandas/tests/io/parser/test_parse_dates.py index d8f362039ba13..700dcde336cd1 100644 --- a/pandas/tests/io/parser/test_parse_dates.py +++ b/pandas/tests/io/parser/test_parse_dates.py @@ -1326,9 +1326,8 @@ def test_read_with_parse_dates_invalid_type(all_parsers, parse_dates): parser.read_csv(StringIO(data), parse_dates=(1,)) -@pytest.mark.parametrize("cache_dates", [True, False]) @pytest.mark.parametrize("value", ["nan", ""]) -def test_bad_date_parse(all_parsers, cache_dates, value): +def test_bad_date_parse(all_parsers, cache, value): # if we have an invalid date make sure that we handle this with # and w/o the cache properly parser = all_parsers @@ -1339,13 +1338,12 @@ def test_bad_date_parse(all_parsers, cache_dates, value): header=None, names=["foo", "bar"], parse_dates=["foo"], - cache_dates=cache_dates, + cache_dates=cache, ) -@pytest.mark.parametrize("cache_dates", [True, False]) @pytest.mark.parametrize("value", ["0"]) -def test_bad_date_parse_with_warning(all_parsers, cache_dates, value): +def test_bad_date_parse_with_warning(all_parsers, cache, value): # if we have an invalid date make sure that we handle this with # and w/o the cache properly. parser = all_parsers @@ -1357,7 +1355,7 @@ def test_bad_date_parse_with_warning(all_parsers, cache_dates, value): # TODO: parse dates directly in pyarrow, see # https://github.com/pandas-dev/pandas/issues/48017 warn = None - elif cache_dates: + elif cache: # Note: warning is not raised if 'cache_dates', because here there is only a # single unique date and hence no risk of inconsistent parsing. warn = None @@ -1370,7 +1368,7 @@ def test_bad_date_parse_with_warning(all_parsers, cache_dates, value): header=None, names=["foo", "bar"], parse_dates=["foo"], - cache_dates=cache_dates, + cache_dates=cache, raise_on_extra_warnings=False, ) diff --git a/pandas/tests/tools/test_to_datetime.py b/pandas/tests/tools/test_to_datetime.py index 0ce1f7b0ff20e..adcb4fe76abe3 100644 --- a/pandas/tests/tools/test_to_datetime.py +++ b/pandas/tests/tools/test_to_datetime.py @@ -62,14 +62,6 @@ ) -@pytest.fixture(params=[True, False]) -def cache(request): - """ - cache keyword to pass to to_datetime. - """ - return request.param - - class TestTimeConversionFormats: def test_to_datetime_readonly(self, writable): # GH#34857 @@ -1585,7 +1577,6 @@ def test_convert_object_to_datetime_with_cache( ) tm.assert_series_equal(result_series, expected_series) - @pytest.mark.parametrize("cache", [True, False]) @pytest.mark.parametrize( "input", [ @@ -3597,7 +3588,6 @@ def test_empty_string_datetime_coerce__unit(): tm.assert_index_equal(expected, result) -@pytest.mark.parametrize("cache", [True, False]) def test_to_datetime_monotonic_increasing_index(cache): # GH28238 cstart = start_caching_at From 07a9a29d3acd4a4ffdb33693f392ebbcd92a4724 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Wed, 20 Dec 2023 15:01:46 -0800 Subject: [PATCH 23/26] Move nogil, parallel, nopython to top level --- pandas/conftest.py | 28 ++++++++++++++++++++++++++++ pandas/tests/groupby/conftest.py | 22 ---------------------- pandas/tests/window/conftest.py | 22 ---------------------- 3 files changed, 28 insertions(+), 44 deletions(-) diff --git a/pandas/conftest.py b/pandas/conftest.py index 44bb3360e824e..b6a7043a44c7a 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -459,6 +459,34 @@ def cache(request): 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. # ---------------------------------------------------------------- diff --git a/pandas/tests/groupby/conftest.py b/pandas/tests/groupby/conftest.py index 1f1401b8dcce3..331dbd85e0f36 100644 --- a/pandas/tests/groupby/conftest.py +++ b/pandas/tests/groupby/conftest.py @@ -133,28 +133,6 @@ def groupby_func(request): return request.param -@pytest.fixture(params=[True, False]) -def parallel(request): - """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): - """nogil keyword argument for numba.jit""" - return request.param - - -@pytest.fixture(params=[True]) -def nopython(request): - """nopython keyword argument for numba.jit""" - return request.param - - @pytest.fixture( params=[ ("mean", {}), diff --git a/pandas/tests/window/conftest.py b/pandas/tests/window/conftest.py index 73ab470ab97a7..fe873b3b74254 100644 --- a/pandas/tests/window/conftest.py +++ b/pandas/tests/window/conftest.py @@ -50,28 +50,6 @@ def min_periods(request): return request.param -@pytest.fixture(params=[True, False]) -def parallel(request): - """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): - """nogil keyword argument for numba.jit""" - return request.param - - -@pytest.fixture(params=[True]) -def nopython(request): - """nopython keyword argument for numba.jit""" - return request.param - - @pytest.fixture(params=[True, False]) def adjust(request): """adjust keyword argument for ewm""" From e5859c8452b6afd7f9eba6d92b60697c4b296b09 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Wed, 20 Dec 2023 15:02:38 -0800 Subject: [PATCH 24/26] Use top level center --- pandas/tests/window/test_rolling.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/tests/window/test_rolling.py b/pandas/tests/window/test_rolling.py index a9a4a2a2bd991..19c24f1c5b189 100644 --- a/pandas/tests/window/test_rolling.py +++ b/pandas/tests/window/test_rolling.py @@ -669,7 +669,6 @@ def test_rolling_datetime(axis, tz_naive_fixture): tm.assert_frame_equal(result, expected) -@pytest.mark.parametrize("center", [True, False]) def test_rolling_window_as_string(center): # see gh-22590 date_today = datetime.now() From 2fb836565bd7402d6be51b41034bbbb26542b5f4 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Wed, 20 Dec 2023 15:34:15 -0800 Subject: [PATCH 25/26] Reuse more fixtures --- pandas/tests/apply/test_str.py | 8 +++----- pandas/tests/arithmetic/test_datetime64.py | 4 ---- pandas/tests/arrays/boolean/test_reduction.py | 1 - pandas/tests/arrays/categorical/test_algos.py | 1 - pandas/tests/arrays/categorical/test_api.py | 1 - pandas/tests/arrays/categorical/test_astype.py | 6 ++---- .../tests/arrays/categorical/test_constructors.py | 2 -- pandas/tests/arrays/categorical/test_dtypes.py | 1 - .../tests/arrays/datetimes/test_constructors.py | 1 - pandas/tests/arrays/integer/test_dtypes.py | 2 -- pandas/tests/base/test_unique.py | 1 - pandas/tests/base/test_value_counts.py | 1 - pandas/tests/dtypes/test_dtypes.py | 15 +++++++-------- pandas/tests/extension/base/methods.py | 1 - pandas/tests/extension/base/setitem.py | 5 ++--- pandas/tests/extension/decimal/test_decimal.py | 3 +-- pandas/tests/extension/test_arrow.py | 1 - pandas/tests/frame/methods/test_astype.py | 5 ++--- pandas/tests/groupby/test_apply.py | 2 -- pandas/tests/groupby/test_groupby_dropna.py | 1 - pandas/tests/groupby/test_missing.py | 1 - .../tests/indexes/datetimes/methods/test_snap.py | 1 - pandas/tests/indexes/test_datetimelike.py | 1 - pandas/tests/interchange/test_impl.py | 1 - pandas/tests/io/json/test_pandas.py | 1 - pandas/tests/resample/test_timedelta.py | 1 - pandas/tests/reshape/test_pivot.py | 1 - .../tests/scalar/timedelta/methods/test_round.py | 1 - .../scalar/timestamp/methods/test_normalize.py | 1 - .../scalar/timestamp/methods/test_replace.py | 2 -- .../tests/scalar/timestamp/methods/test_round.py | 2 -- .../scalar/timestamp/methods/test_tz_localize.py | 4 ---- .../tests/tseries/frequencies/test_inference.py | 1 - .../tests/tseries/offsets/test_business_hour.py | 1 - pandas/tests/window/test_rolling.py | 1 - 35 files changed, 17 insertions(+), 65 deletions(-) diff --git a/pandas/tests/apply/test_str.py b/pandas/tests/apply/test_str.py index 17e8322dc40e1..4b3c86378734a 100644 --- a/pandas/tests/apply/test_str.py +++ b/pandas/tests/apply/test_str.py @@ -43,14 +43,12 @@ 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 -@pytest.mark.parametrize("op", ["mean", "median", "std", "var"]) @pytest.mark.parametrize("how", ["agg", "apply"]) def test_apply_np_reducer(op, how): # GH 39116 diff --git a/pandas/tests/arithmetic/test_datetime64.py b/pandas/tests/arithmetic/test_datetime64.py index dbff88dc6f4f6..b4e8d09c18163 100644 --- a/pandas/tests/arithmetic/test_datetime64.py +++ b/pandas/tests/arithmetic/test_datetime64.py @@ -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 @@ -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( @@ -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 @@ -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( [ diff --git a/pandas/tests/arrays/boolean/test_reduction.py b/pandas/tests/arrays/boolean/test_reduction.py index dd8c3eda9ed05..7071c6f8844e4 100644 --- a/pandas/tests/arrays/boolean/test_reduction.py +++ b/pandas/tests/arrays/boolean/test_reduction.py @@ -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) diff --git a/pandas/tests/arrays/categorical/test_algos.py b/pandas/tests/arrays/categorical/test_algos.py index d4c19a4970135..69c3364c7e98e 100644 --- a/pandas/tests/arrays/categorical/test_algos.py +++ b/pandas/tests/arrays/categorical/test_algos.py @@ -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( diff --git a/pandas/tests/arrays/categorical/test_api.py b/pandas/tests/arrays/categorical/test_api.py index b4215b4a6fe21..58411b00f92e7 100644 --- a/pandas/tests/arrays/categorical/test_api.py +++ b/pandas/tests/arrays/categorical/test_api.py @@ -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) diff --git a/pandas/tests/arrays/categorical/test_astype.py b/pandas/tests/arrays/categorical/test_astype.py index a2a53af6ab1ad..7cfd8ec8dfadf 100644 --- a/pandas/tests/arrays/categorical/test_astype.py +++ b/pandas/tests/arrays/categorical/test_astype.py @@ -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) @@ -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) diff --git a/pandas/tests/arrays/categorical/test_constructors.py b/pandas/tests/arrays/categorical/test_constructors.py index 373f1c95463fc..03678fb64d3e9 100644 --- a/pandas/tests/arrays/categorical/test_constructors.py +++ b/pandas/tests/arrays/categorical/test_constructors.py @@ -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" @@ -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) diff --git a/pandas/tests/arrays/categorical/test_dtypes.py b/pandas/tests/arrays/categorical/test_dtypes.py index 525663cad1745..f2f2851c22794 100644 --- a/pandas/tests/arrays/categorical/test_dtypes.py +++ b/pandas/tests/arrays/categorical/test_dtypes.py @@ -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) diff --git a/pandas/tests/arrays/datetimes/test_constructors.py b/pandas/tests/arrays/datetimes/test_constructors.py index 97fa6e8d529b7..e14cc6eba5857 100644 --- a/pandas/tests/arrays/datetimes/test_constructors.py +++ b/pandas/tests/arrays/datetimes/test_constructors.py @@ -142,7 +142,6 @@ def test_copy(self): arr = DatetimeArray(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(data) diff --git a/pandas/tests/arrays/integer/test_dtypes.py b/pandas/tests/arrays/integer/test_dtypes.py index e3848cdfe3aa9..99db05229a57d 100644 --- a/pandas/tests/arrays/integer/test_dtypes.py +++ b/pandas/tests/arrays/integer/test_dtypes.py @@ -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 @@ -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 diff --git a/pandas/tests/base/test_unique.py b/pandas/tests/base/test_unique.py index d3fe144f70cfc..3a8ed471f9dc0 100644 --- a/pandas/tests/base/test_unique.py +++ b/pandas/tests/base/test_unique.py @@ -116,7 +116,6 @@ def test_unique_bad_unicode(index_or_series): tm.assert_numpy_array_equal(result, expected) -@pytest.mark.parametrize("dropna", [True, False]) def test_nunique_dropna(dropna): # GH37566 ser = pd.Series(["yes", "yes", pd.NA, np.nan, None, pd.NaT]) diff --git a/pandas/tests/base/test_value_counts.py b/pandas/tests/base/test_value_counts.py index 2729666398877..a0b0bdfdb46d8 100644 --- a/pandas/tests/base/test_value_counts.py +++ b/pandas/tests/base/test_value_counts.py @@ -329,7 +329,6 @@ def test_value_counts_timedelta64(index_or_series, unit): tm.assert_series_equal(result2, expected_s) -@pytest.mark.parametrize("dropna", [True, False]) def test_value_counts_with_nan(dropna, index_or_series): # GH31944 klass = index_or_series diff --git a/pandas/tests/dtypes/test_dtypes.py b/pandas/tests/dtypes/test_dtypes.py index 0dad0b05303ad..c52d49034f74e 100644 --- a/pandas/tests/dtypes/test_dtypes.py +++ b/pandas/tests/dtypes/test_dtypes.py @@ -959,25 +959,24 @@ def test_same_categories_different_order(self): c2 = CategoricalDtype(["b", "a"], ordered=True) assert c1 is not c2 - @pytest.mark.parametrize("ordered1", [True, False, None]) @pytest.mark.parametrize("ordered2", [True, False, None]) - def test_categorical_equality(self, ordered1, ordered2): + def test_categorical_equality(self, ordered, ordered2): # same categories, same order # any combination of None/False are equal # True/True is the only combination with True that are equal - c1 = CategoricalDtype(list("abc"), ordered1) + c1 = CategoricalDtype(list("abc"), ordered) c2 = CategoricalDtype(list("abc"), ordered2) result = c1 == c2 - expected = bool(ordered1) is bool(ordered2) + expected = bool(ordered) is bool(ordered2) assert result is expected # same categories, different order # any combination of None/False are equal (order doesn't matter) # any combination with True are not equal (different order of cats) - c1 = CategoricalDtype(list("abc"), ordered1) + c1 = CategoricalDtype(list("abc"), ordered) c2 = CategoricalDtype(list("cab"), ordered2) result = c1 == c2 - expected = (bool(ordered1) is False) and (bool(ordered2) is False) + expected = (bool(ordered) is False) and (bool(ordered2) is False) assert result is expected # different categories @@ -985,9 +984,9 @@ def test_categorical_equality(self, ordered1, ordered2): assert c1 != c2 # none categories - c1 = CategoricalDtype(list("abc"), ordered1) + c1 = CategoricalDtype(list("abc"), ordered) c2 = CategoricalDtype(None, ordered2) - c3 = CategoricalDtype(None, ordered1) + c3 = CategoricalDtype(None, ordered) assert c1 != c2 assert c2 != c1 assert c2 == c3 diff --git a/pandas/tests/extension/base/methods.py b/pandas/tests/extension/base/methods.py index 6de5c97cbfb5e..ba247f51e5f1b 100644 --- a/pandas/tests/extension/base/methods.py +++ b/pandas/tests/extension/base/methods.py @@ -37,7 +37,6 @@ def test_value_counts_default_dropna(self, data): kwarg = sig.parameters["dropna"] assert kwarg.default is True - @pytest.mark.parametrize("dropna", [True, False]) def test_value_counts(self, all_data, dropna): all_data = all_data[:10] if dropna: diff --git a/pandas/tests/extension/base/setitem.py b/pandas/tests/extension/base/setitem.py index ca19845041e23..c3259fe0fb4c9 100644 --- a/pandas/tests/extension/base/setitem.py +++ b/pandas/tests/extension/base/setitem.py @@ -105,10 +105,9 @@ def test_setitem_sequence_broadcasts(self, data, box_in_series): assert data[0] == data[2] assert data[1] == data[2] - @pytest.mark.parametrize("setter", ["loc", "iloc"]) - def test_setitem_scalar(self, data, setter): + def test_setitem_scalar(self, data, indexer_li): arr = pd.Series(data) - setter = getattr(arr, setter) + setter = indexer_li(arr) setter[0] = data[1] assert arr[0] == data[1] diff --git a/pandas/tests/extension/decimal/test_decimal.py b/pandas/tests/extension/decimal/test_decimal.py index b3c57ee49a724..49f29b2194cae 100644 --- a/pandas/tests/extension/decimal/test_decimal.py +++ b/pandas/tests/extension/decimal/test_decimal.py @@ -227,8 +227,7 @@ def test_fillna_copy_series(self, data_missing, using_copy_on_write): with tm.assert_produces_warning(warn, match=msg, check_stacklevel=False): super().test_fillna_copy_series(data_missing) - @pytest.mark.parametrize("dropna", [True, False]) - def test_value_counts(self, all_data, dropna, request): + def test_value_counts(self, all_data, dropna): all_data = all_data[:10] if dropna: other = np.array(all_data[~all_data.isna()]) diff --git a/pandas/tests/extension/test_arrow.py b/pandas/tests/extension/test_arrow.py index 2634d40639661..d2bd0d1eca554 100644 --- a/pandas/tests/extension/test_arrow.py +++ b/pandas/tests/extension/test_arrow.py @@ -2300,7 +2300,6 @@ def test_str_extract_expand(): tm.assert_series_equal(result, expected) -@pytest.mark.parametrize("unit", ["ns", "us", "ms", "s"]) def test_duration_from_strings_with_nat(unit): # GH51175 strings = ["1000", "NaT"] diff --git a/pandas/tests/frame/methods/test_astype.py b/pandas/tests/frame/methods/test_astype.py index 5a1e3cd786f84..b73c759518b0e 100644 --- a/pandas/tests/frame/methods/test_astype.py +++ b/pandas/tests/frame/methods/test_astype.py @@ -498,11 +498,10 @@ def test_astype_to_datetime_unit(self, unit): assert exp_dta.dtype == dtype tm.assert_extension_array_equal(res_dta, exp_dta) - @pytest.mark.parametrize("unit", ["ns"]) - def test_astype_to_timedelta_unit_ns(self, unit): + def test_astype_to_timedelta_unit_ns(self): # preserver the timedelta conversion # GH#19223 - dtype = f"m8[{unit}]" + dtype = "m8[ns]" arr = np.array([[1, 2, 3]], dtype=dtype) df = DataFrame(arr) result = df.astype(dtype) diff --git a/pandas/tests/groupby/test_apply.py b/pandas/tests/groupby/test_apply.py index 34b6e7c4cde5f..f4b228eb5b326 100644 --- a/pandas/tests/groupby/test_apply.py +++ b/pandas/tests/groupby/test_apply.py @@ -1282,7 +1282,6 @@ def test_apply_by_cols_equals_apply_by_rows_transposed(): tm.assert_frame_equal(by_cols, df) -@pytest.mark.parametrize("dropna", [True, False]) def test_apply_dropna_with_indexed_same(dropna): # GH 38227 # GH#43205 @@ -1394,7 +1393,6 @@ def test_groupby_apply_to_series_name(): tm.assert_series_equal(result, expected) -@pytest.mark.parametrize("dropna", [True, False]) def test_apply_na(dropna): # GH#28984 df = DataFrame( diff --git a/pandas/tests/groupby/test_groupby_dropna.py b/pandas/tests/groupby/test_groupby_dropna.py index 73638eba0a3b3..ca097bc2be8bb 100644 --- a/pandas/tests/groupby/test_groupby_dropna.py +++ b/pandas/tests/groupby/test_groupby_dropna.py @@ -167,7 +167,6 @@ def test_groupby_dropna_series_by(dropna, expected): tm.assert_series_equal(result, expected) -@pytest.mark.parametrize("dropna", (False, True)) def test_grouper_dropna_propagation(dropna): # GH 36604 df = pd.DataFrame({"A": [0, 0, 1, None], "B": [1, 2, 3, None]}) diff --git a/pandas/tests/groupby/test_missing.py b/pandas/tests/groupby/test_missing.py index 3180a92be1236..6c029c10817d9 100644 --- a/pandas/tests/groupby/test_missing.py +++ b/pandas/tests/groupby/test_missing.py @@ -109,7 +109,6 @@ def test_fill_consistency(): @pytest.mark.parametrize("method", ["ffill", "bfill"]) -@pytest.mark.parametrize("dropna", [True, False]) @pytest.mark.parametrize("has_nan_group", [True, False]) def test_ffill_handles_nan_groups(dropna, method, has_nan_group): # GH 34725 diff --git a/pandas/tests/indexes/datetimes/methods/test_snap.py b/pandas/tests/indexes/datetimes/methods/test_snap.py index 7064e9e7993f8..651e4383a3fac 100644 --- a/pandas/tests/indexes/datetimes/methods/test_snap.py +++ b/pandas/tests/indexes/datetimes/methods/test_snap.py @@ -9,7 +9,6 @@ @pytest.mark.parametrize("tz", [None, "Asia/Shanghai", "Europe/Berlin"]) @pytest.mark.parametrize("name", [None, "my_dti"]) -@pytest.mark.parametrize("unit", ["ns", "us", "ms", "s"]) def test_dti_snap(name, tz, unit): dti = DatetimeIndex( [ diff --git a/pandas/tests/indexes/test_datetimelike.py b/pandas/tests/indexes/test_datetimelike.py index 21a686e8bc05b..330ea50dc1373 100644 --- a/pandas/tests/indexes/test_datetimelike.py +++ b/pandas/tests/indexes/test_datetimelike.py @@ -162,7 +162,6 @@ def test_where_cast_str(self, simple_index): result = index.where(mask, ["foo"]) tm.assert_index_equal(result, expected) - @pytest.mark.parametrize("unit", ["ns", "us", "ms", "s"]) def test_diff(self, unit): # GH 55080 dti = pd.to_datetime([10, 20, 30], unit=unit).as_unit(unit) diff --git a/pandas/tests/interchange/test_impl.py b/pandas/tests/interchange/test_impl.py index 15c2b8d000b37..8bc6b48922a4f 100644 --- a/pandas/tests/interchange/test_impl.py +++ b/pandas/tests/interchange/test_impl.py @@ -304,7 +304,6 @@ def test_multi_chunk_pyarrow() -> None: @pytest.mark.parametrize("tz", ["UTC", "US/Pacific"]) -@pytest.mark.parametrize("unit", ["s", "ms", "us", "ns"]) def test_datetimetzdtype(tz, unit): # GH 54239 tz_data = ( diff --git a/pandas/tests/io/json/test_pandas.py b/pandas/tests/io/json/test_pandas.py index 9d608165ede6c..ce9b601797abd 100644 --- a/pandas/tests/io/json/test_pandas.py +++ b/pandas/tests/io/json/test_pandas.py @@ -957,7 +957,6 @@ def test_date_format_series_raises(self, datetime_series): with pytest.raises(ValueError, match=msg): ts.to_json(date_format="iso", date_unit="foo") - @pytest.mark.parametrize("unit", ["s", "ms", "us", "ns"]) def test_date_unit(self, unit, datetime_frame): df = datetime_frame df["date"] = Timestamp("20130101 20:43:42").as_unit("ns") diff --git a/pandas/tests/resample/test_timedelta.py b/pandas/tests/resample/test_timedelta.py index 7c70670d42908..309810b656ed3 100644 --- a/pandas/tests/resample/test_timedelta.py +++ b/pandas/tests/resample/test_timedelta.py @@ -176,7 +176,6 @@ def test_resample_with_timedelta_yields_no_empty_groups(duplicates): tm.assert_frame_equal(result, expected) -@pytest.mark.parametrize("unit", ["s", "ms", "us", "ns"]) def test_resample_quantile_timedelta(unit): # GH: 29485 dtype = np.dtype(f"m8[{unit}]") diff --git a/pandas/tests/reshape/test_pivot.py b/pandas/tests/reshape/test_pivot.py index 5ca0da3991b8e..3cadf9c22175f 100644 --- a/pandas/tests/reshape/test_pivot.py +++ b/pandas/tests/reshape/test_pivot.py @@ -2318,7 +2318,6 @@ def test_pivot_table_with_margins_and_numeric_columns(self): tm.assert_frame_equal(result, expected) - @pytest.mark.parametrize("dropna", [True, False]) def test_pivot_ea_dtype_dropna(self, dropna): # GH#47477 df = DataFrame({"x": "a", "y": "b", "age": Series([20, 40], dtype="Int64")}) diff --git a/pandas/tests/scalar/timedelta/methods/test_round.py b/pandas/tests/scalar/timedelta/methods/test_round.py index 4beb39510413c..a8ca7f741d966 100644 --- a/pandas/tests/scalar/timedelta/methods/test_round.py +++ b/pandas/tests/scalar/timedelta/methods/test_round.py @@ -168,7 +168,6 @@ def checker(ts, nanos, unit): nanos = 24 * 60 * 60 * 1_000_000_000 checker(td, nanos, "D") - @pytest.mark.parametrize("unit", ["ns", "us", "ms", "s"]) def test_round_non_nano(self, unit): td = Timedelta("1 days 02:34:57").as_unit(unit) diff --git a/pandas/tests/scalar/timestamp/methods/test_normalize.py b/pandas/tests/scalar/timestamp/methods/test_normalize.py index e097c9673e17a..60f249c602bd6 100644 --- a/pandas/tests/scalar/timestamp/methods/test_normalize.py +++ b/pandas/tests/scalar/timestamp/methods/test_normalize.py @@ -6,7 +6,6 @@ class TestTimestampNormalize: @pytest.mark.parametrize("arg", ["2013-11-30", "2013-11-30 12:00:00"]) - @pytest.mark.parametrize("unit", ["ns", "us", "ms", "s"]) def test_normalize(self, tz_naive_fixture, arg, unit): tz = tz_naive_fixture ts = Timestamp(arg, tz=tz).as_unit(unit) diff --git a/pandas/tests/scalar/timestamp/methods/test_replace.py b/pandas/tests/scalar/timestamp/methods/test_replace.py index 8a208455edc82..d67de79a8dd10 100644 --- a/pandas/tests/scalar/timestamp/methods/test_replace.py +++ b/pandas/tests/scalar/timestamp/methods/test_replace.py @@ -157,7 +157,6 @@ def test_replace_across_dst(self, tz, normalize): ts2b = normalize(ts2) assert ts2 == ts2b - @pytest.mark.parametrize("unit", ["ns", "us", "ms", "s"]) def test_replace_dst_border(self, unit): # Gh 7825 t = Timestamp("2013-11-3", tz="America/Chicago").as_unit(unit) @@ -168,7 +167,6 @@ def test_replace_dst_border(self, unit): @pytest.mark.parametrize("fold", [0, 1]) @pytest.mark.parametrize("tz", ["dateutil/Europe/London", "Europe/London"]) - @pytest.mark.parametrize("unit", ["ns", "us", "ms", "s"]) def test_replace_dst_fold(self, fold, tz, unit): # GH 25017 d = datetime(2019, 10, 27, 2, 30) diff --git a/pandas/tests/scalar/timestamp/methods/test_round.py b/pandas/tests/scalar/timestamp/methods/test_round.py index d10ee18b47f19..59c0fe8bbebfb 100644 --- a/pandas/tests/scalar/timestamp/methods/test_round.py +++ b/pandas/tests/scalar/timestamp/methods/test_round.py @@ -147,7 +147,6 @@ def test_round_minute_freq(self, test_input, freq, expected, rounder): result = func(freq) assert result == expected - @pytest.mark.parametrize("unit", ["ns", "us", "ms", "s"]) def test_ceil(self, unit): dt = Timestamp("20130101 09:10:11").as_unit(unit) result = dt.ceil("D") @@ -155,7 +154,6 @@ def test_ceil(self, unit): assert result == expected assert result._creso == dt._creso - @pytest.mark.parametrize("unit", ["ns", "us", "ms", "s"]) def test_floor(self, unit): dt = Timestamp("20130101 09:10:11").as_unit(unit) result = dt.floor("D") diff --git a/pandas/tests/scalar/timestamp/methods/test_tz_localize.py b/pandas/tests/scalar/timestamp/methods/test_tz_localize.py index 9df0a023730de..cf221822fe8bf 100644 --- a/pandas/tests/scalar/timestamp/methods/test_tz_localize.py +++ b/pandas/tests/scalar/timestamp/methods/test_tz_localize.py @@ -49,7 +49,6 @@ def test_tz_localize_pushes_out_of_bounds(self): with pytest.raises(OutOfBoundsDatetime, match=msg): Timestamp.max.tz_localize("US/Pacific") - @pytest.mark.parametrize("unit", ["ns", "us", "ms", "s"]) def test_tz_localize_ambiguous_bool(self, unit): # make sure that we are correctly accepting bool values as ambiguous # GH#14402 @@ -294,7 +293,6 @@ def test_timestamp_tz_localize(self, tz): ], ) @pytest.mark.parametrize("tz_type", ["", "dateutil/"]) - @pytest.mark.parametrize("unit", ["ns", "us", "ms", "s"]) def test_timestamp_tz_localize_nonexistent_shift( self, start_ts, tz, end_ts, shift, tz_type, unit ): @@ -326,7 +324,6 @@ def test_timestamp_tz_localize_nonexistent_shift_invalid(self, offset, warsaw): with pytest.raises(ValueError, match=msg): ts.tz_localize(tz, nonexistent=timedelta(seconds=offset)) - @pytest.mark.parametrize("unit", ["ns", "us", "ms", "s"]) def test_timestamp_tz_localize_nonexistent_NaT(self, warsaw, unit): # GH 8917 tz = warsaw @@ -334,7 +331,6 @@ def test_timestamp_tz_localize_nonexistent_NaT(self, warsaw, unit): result = ts.tz_localize(tz, nonexistent="NaT") assert result is NaT - @pytest.mark.parametrize("unit", ["ns", "us", "ms", "s"]) def test_timestamp_tz_localize_nonexistent_raise(self, warsaw, unit): # GH 8917 tz = warsaw diff --git a/pandas/tests/tseries/frequencies/test_inference.py b/pandas/tests/tseries/frequencies/test_inference.py index 45741e852fef7..e96af6c6faf35 100644 --- a/pandas/tests/tseries/frequencies/test_inference.py +++ b/pandas/tests/tseries/frequencies/test_inference.py @@ -229,7 +229,6 @@ def test_infer_freq_index(freq, expected): }.items() ), ) -@pytest.mark.parametrize("unit", ["s", "ms", "us", "ns"]) def test_infer_freq_tz(tz_naive_fixture, expected, dates, unit): # see gh-7310, GH#55609 tz = tz_naive_fixture diff --git a/pandas/tests/tseries/offsets/test_business_hour.py b/pandas/tests/tseries/offsets/test_business_hour.py index 2779100f5355c..e675977c6fab4 100644 --- a/pandas/tests/tseries/offsets/test_business_hour.py +++ b/pandas/tests/tseries/offsets/test_business_hour.py @@ -947,7 +947,6 @@ def test_apply_nanoseconds(self): assert_offset_equal(offset, base, expected) @pytest.mark.parametrize("td_unit", ["s", "ms", "us", "ns"]) - @pytest.mark.parametrize("unit", ["s", "ms", "us", "ns"]) def test_bday_ignores_timedeltas(self, unit, td_unit): # GH#55608 idx = date_range("2010/02/01", "2010/02/10", freq="12h", unit=unit) diff --git a/pandas/tests/window/test_rolling.py b/pandas/tests/window/test_rolling.py index 19c24f1c5b189..7ab6e7863ad81 100644 --- a/pandas/tests/window/test_rolling.py +++ b/pandas/tests/window/test_rolling.py @@ -1945,7 +1945,6 @@ def test_numeric_only_corr_cov_series(kernel, use_arg, numeric_only, dtype): tm.assert_series_equal(result, expected) -@pytest.mark.parametrize("unit", ["s", "ms", "us", "ns"]) @pytest.mark.parametrize("tz", [None, "UTC", "Europe/Prague"]) def test_rolling_timedelta_window_non_nanoseconds(unit, tz): # Test Sum, GH#55106 From 9289d87fb360483879aebfac126d6ef9e06dfde1 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Wed, 20 Dec 2023 17:39:10 -0800 Subject: [PATCH 26/26] Fix errors --- pandas/tests/apply/test_str.py | 1 + pandas/tests/arrays/test_datetimes.py | 5 +++++ pandas/tests/extension/test_categorical.py | 4 ---- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/pandas/tests/apply/test_str.py b/pandas/tests/apply/test_str.py index 4b3c86378734a..e9967b75becce 100644 --- a/pandas/tests/apply/test_str.py +++ b/pandas/tests/apply/test_str.py @@ -49,6 +49,7 @@ def test_with_string_args(datetime_series, all_numeric_reductions): assert result == expected +@pytest.mark.parametrize("op", ["mean", "median", "std", "var"]) @pytest.mark.parametrize("how", ["agg", "apply"]) def test_apply_np_reducer(op, how): # GH 39116 diff --git a/pandas/tests/arrays/test_datetimes.py b/pandas/tests/arrays/test_datetimes.py index 675d500ca4401..db86f62a10484 100644 --- a/pandas/tests/arrays/test_datetimes.py +++ b/pandas/tests/arrays/test_datetimes.py @@ -28,6 +28,11 @@ class TestNonNano: + @pytest.fixture(params=["s", "ms", "us"]) + def unit(self, request): + """Fixture returning parametrized time units""" + return request.param + @pytest.fixture def dtype(self, unit, tz_naive_fixture): tz = tz_naive_fixture diff --git a/pandas/tests/extension/test_categorical.py b/pandas/tests/extension/test_categorical.py index 7598aca10bad4..a8731da2e70f7 100644 --- a/pandas/tests/extension/test_categorical.py +++ b/pandas/tests/extension/test_categorical.py @@ -122,10 +122,6 @@ def test_getitem_scalar(self, data): # to break things by changing. super().test_getitem_scalar(data) - @pytest.mark.xfail(reason="Unobserved categories included") - def test_value_counts(self, all_data, dropna): - return super().test_value_counts(all_data, dropna) - def test_combine_add(self, data_repeated): # GH 20825 # When adding categoricals in combine, result is a string