diff --git a/pandas/tests/window/conftest.py b/pandas/tests/window/conftest.py index 09233e3f31c89..f2832652ed58f 100644 --- a/pandas/tests/window/conftest.py +++ b/pandas/tests/window/conftest.py @@ -12,7 +12,6 @@ DataFrame, Series, bdate_range, - to_datetime, ) @@ -22,27 +21,6 @@ def raw(request): return request.param -@pytest.fixture( - params=[ - "triang", - "blackman", - "hamming", - "bartlett", - "bohman", - "blackmanharris", - "nuttall", - "barthann", - ] -) -def win_types(request): - return request.param - - -@pytest.fixture(params=["kaiser", "gaussian", "general_gaussian", "exponential"]) -def win_types_special(request): - return request.param - - @pytest.fixture( params=[ "sum", @@ -62,28 +40,6 @@ def arithmetic_win_operators(request): return request.param -@pytest.fixture( - params=[ - ["sum", {}], - ["mean", {}], - ["median", {}], - ["max", {}], - ["min", {}], - ["var", {}], - ["var", {"ddof": 0}], - ["std", {}], - ["std", {"ddof": 0}], - ] -) -def arithmetic_numba_supported_operators(request): - return request.param - - -@pytest.fixture(params=["right", "left", "both", "neither"]) -def closed(request): - return request.param - - @pytest.fixture(params=[True, False]) def center(request): return request.param @@ -94,12 +50,6 @@ def min_periods(request): return request.param -@pytest.fixture(params=["single", "table"]) -def method(request): - """method keyword in rolling/expanding/ewm constructor""" - return request.param - - @pytest.fixture(params=[True, False]) def parallel(request): """parallel keyword argument for numba.jit""" @@ -152,95 +102,12 @@ def engine_and_raw(request): return request.param -@pytest.fixture -def times_frame(): - """Frame for testing times argument in EWM groupby.""" - return DataFrame( - { - "A": ["a", "b", "c", "a", "b", "c", "a", "b", "c", "a"], - "B": [0, 0, 0, 1, 1, 1, 2, 2, 2, 3], - "C": to_datetime( - [ - "2020-01-01", - "2020-01-01", - "2020-01-01", - "2020-01-02", - "2020-01-10", - "2020-01-22", - "2020-01-03", - "2020-01-23", - "2020-01-23", - "2020-01-04", - ] - ), - } - ) - - @pytest.fixture(params=["1 day", timedelta(days=1)]) def halflife_with_times(request): """Halflife argument for EWM when times is specified.""" return request.param -@pytest.fixture( - params=[ - "object", - "category", - "int8", - "int16", - "int32", - "int64", - "uint8", - "uint16", - "uint32", - "uint64", - "float16", - "float32", - "float64", - "m8[ns]", - "M8[ns]", - "datetime64[ns, UTC]", - ] -) -def dtypes(request): - """Dtypes for window tests""" - return request.param - - -@pytest.fixture( - params=[ - DataFrame([[2, 4], [1, 2], [5, 2], [8, 1]], columns=[1, 0]), - DataFrame([[2, 4], [1, 2], [5, 2], [8, 1]], columns=[1, 1]), - DataFrame([[2, 4], [1, 2], [5, 2], [8, 1]], columns=["C", "C"]), - DataFrame([[2, 4], [1, 2], [5, 2], [8, 1]], columns=[1.0, 0]), - DataFrame([[2, 4], [1, 2], [5, 2], [8, 1]], columns=[0.0, 1]), - DataFrame([[2, 4], [1, 2], [5, 2], [8, 1]], columns=["C", 1]), - DataFrame([[2.0, 4.0], [1.0, 2.0], [5.0, 2.0], [8.0, 1.0]], columns=[1, 0.0]), - DataFrame([[2, 4.0], [1, 2.0], [5, 2.0], [8, 1.0]], columns=[0, 1.0]), - DataFrame([[2, 4], [1, 2], [5, 2], [8, 1.0]], columns=[1.0, "X"]), - ] -) -def pairwise_frames(request): - """Pairwise frames test_pairwise""" - return request.param - - -@pytest.fixture -def pairwise_target_frame(): - """Pairwise target frame for test_pairwise""" - return DataFrame([[2, 4], [1, 2], [5, 2], [8, 1]], columns=[0, 1]) - - -@pytest.fixture -def pairwise_other_frame(): - """Pairwise other frame for test_pairwise""" - return DataFrame( - [[None, 1, 1], [None, 1, 2], [None, 3, 2], [None, 8, 1]], - columns=["Y", "Z", "X"], - ) - - @pytest.fixture def series(): """Make mocked series as fixture.""" diff --git a/pandas/tests/window/moments/conftest.py b/pandas/tests/window/moments/conftest.py index 8f7c20fe03a02..fccf80c3c7a58 100644 --- a/pandas/tests/window/moments/conftest.py +++ b/pandas/tests/window/moments/conftest.py @@ -41,7 +41,6 @@ def is_constant(x): for obj in itertools.chain(create_series(), create_dataframes()) if is_constant(obj) ), - scope="module", ) def consistent_data(request): return request.param @@ -68,12 +67,6 @@ def all_data(request): return request.param -@pytest.fixture(params=[(1, 0), (5, 1)]) -def rolling_consistency_cases(request): - """window, min_periods""" - return request.param - - @pytest.fixture(params=[0, 2]) def min_periods(request): return request.param diff --git a/pandas/tests/window/moments/test_moments_consistency_rolling.py b/pandas/tests/window/moments/test_moments_consistency_rolling.py index daca19b0993bf..62bfc66b124f3 100644 --- a/pandas/tests/window/moments/test_moments_consistency_rolling.py +++ b/pandas/tests/window/moments/test_moments_consistency_rolling.py @@ -13,6 +13,12 @@ def all_na(x): return x.isnull().all().all() +@pytest.fixture(params=[(1, 0), (5, 1)]) +def rolling_consistency_cases(request): + """window, min_periods""" + return request.param + + @pytest.mark.parametrize("f", [lambda v: Series(v).sum(), np.nansum, np.sum]) def test_rolling_apply_consistency_sum( request, all_data, rolling_consistency_cases, center, f diff --git a/pandas/tests/window/test_dtypes.py b/pandas/tests/window/test_dtypes.py index 02b5f8a313825..80a96c3a8cee9 100644 --- a/pandas/tests/window/test_dtypes.py +++ b/pandas/tests/window/test_dtypes.py @@ -24,6 +24,31 @@ def get_dtype(dtype, coerce_int=None): return pandas_dtype(dtype) +@pytest.fixture( + params=[ + "object", + "category", + "int8", + "int16", + "int32", + "int64", + "uint8", + "uint16", + "uint32", + "uint64", + "float16", + "float32", + "float64", + "m8[ns]", + "M8[ns]", + "datetime64[ns, UTC]", + ] +) +def dtypes(request): + """Dtypes for window tests""" + return request.param + + @pytest.mark.parametrize( "method, data, expected_data, coerce_int, min_periods", [ diff --git a/pandas/tests/window/test_groupby.py b/pandas/tests/window/test_groupby.py index 6ec19e4899d53..5125587df9ea2 100644 --- a/pandas/tests/window/test_groupby.py +++ b/pandas/tests/window/test_groupby.py @@ -15,6 +15,31 @@ from pandas.core.groupby.groupby import get_groupby +@pytest.fixture +def times_frame(): + """Frame for testing times argument in EWM groupby.""" + return DataFrame( + { + "A": ["a", "b", "c", "a", "b", "c", "a", "b", "c", "a"], + "B": [0, 0, 0, 1, 1, 1, 2, 2, 2, 3], + "C": to_datetime( + [ + "2020-01-01", + "2020-01-01", + "2020-01-01", + "2020-01-02", + "2020-01-10", + "2020-01-22", + "2020-01-03", + "2020-01-23", + "2020-01-23", + "2020-01-04", + ] + ), + } + ) + + class TestRolling: def setup_method(self): self.frame = DataFrame({"A": [1] * 20 + [2] * 12 + [3] * 8, "B": np.arange(40)}) diff --git a/pandas/tests/window/test_numba.py b/pandas/tests/window/test_numba.py index a14515ca9c018..a9e38751c9a2f 100644 --- a/pandas/tests/window/test_numba.py +++ b/pandas/tests/window/test_numba.py @@ -14,6 +14,29 @@ from pandas.core.util.numba_ import NUMBA_FUNC_CACHE +@pytest.fixture(params=["single", "table"]) +def method(request): + """method keyword in rolling/expanding/ewm constructor""" + return request.param + + +@pytest.fixture( + params=[ + ["sum", {}], + ["mean", {}], + ["median", {}], + ["max", {}], + ["min", {}], + ["var", {}], + ["var", {"ddof": 0}], + ["std", {}], + ["std", {"ddof": 0}], + ] +) +def arithmetic_numba_supported_operators(request): + return request.param + + @td.skip_if_no("numba") @pytest.mark.filterwarnings("ignore:\n") # Filter warnings when parallel=True and the function can't be parallelized by Numba diff --git a/pandas/tests/window/test_pairwise.py b/pandas/tests/window/test_pairwise.py index 77ff6ae03d836..6c3f3f7075ce0 100644 --- a/pandas/tests/window/test_pairwise.py +++ b/pandas/tests/window/test_pairwise.py @@ -14,6 +14,39 @@ from pandas.core.algorithms import safe_sort +@pytest.fixture( + params=[ + DataFrame([[2, 4], [1, 2], [5, 2], [8, 1]], columns=[1, 0]), + DataFrame([[2, 4], [1, 2], [5, 2], [8, 1]], columns=[1, 1]), + DataFrame([[2, 4], [1, 2], [5, 2], [8, 1]], columns=["C", "C"]), + DataFrame([[2, 4], [1, 2], [5, 2], [8, 1]], columns=[1.0, 0]), + DataFrame([[2, 4], [1, 2], [5, 2], [8, 1]], columns=[0.0, 1]), + DataFrame([[2, 4], [1, 2], [5, 2], [8, 1]], columns=["C", 1]), + DataFrame([[2.0, 4.0], [1.0, 2.0], [5.0, 2.0], [8.0, 1.0]], columns=[1, 0.0]), + DataFrame([[2, 4.0], [1, 2.0], [5, 2.0], [8, 1.0]], columns=[0, 1.0]), + DataFrame([[2, 4], [1, 2], [5, 2], [8, 1.0]], columns=[1.0, "X"]), + ] +) +def pairwise_frames(request): + """Pairwise frames test_pairwise""" + return request.param + + +@pytest.fixture +def pairwise_target_frame(): + """Pairwise target frame for test_pairwise""" + return DataFrame([[2, 4], [1, 2], [5, 2], [8, 1]], columns=[0, 1]) + + +@pytest.fixture +def pairwise_other_frame(): + """Pairwise other frame for test_pairwise""" + return DataFrame( + [[None, 1, 1], [None, 1, 2], [None, 3, 2], [None, 8, 1]], + columns=["Y", "Z", "X"], + ) + + def test_rolling_cov(series): A = series B = A + np.random.randn(len(A)) diff --git a/pandas/tests/window/test_rolling.py b/pandas/tests/window/test_rolling.py index 31dbcdfce44e7..ced163178f73a 100644 --- a/pandas/tests/window/test_rolling.py +++ b/pandas/tests/window/test_rolling.py @@ -132,6 +132,7 @@ def test_numpy_compat(method): getattr(r, method)(dtype=np.float64) +@pytest.mark.parametrize("closed", ["right", "left", "both", "neither"]) def test_closed_fixed(closed, arithmetic_win_operators): # GH 34315 func_name = arithmetic_win_operators diff --git a/pandas/tests/window/test_timeseries_window.py b/pandas/tests/window/test_timeseries_window.py index c94c418c3d9a7..f51764e04715a 100644 --- a/pandas/tests/window/test_timeseries_window.py +++ b/pandas/tests/window/test_timeseries_window.py @@ -20,7 +20,7 @@ class TestRollingTS: # rolling time-series friendly # xref GH13327 - def setup_method(self, method): + def setup_method(self): self.regular = DataFrame( {"A": date_range("20130101", periods=5, freq="s"), "B": range(5)} diff --git a/pandas/tests/window/test_win_type.py b/pandas/tests/window/test_win_type.py index 6e0edc9e8500c..03ea745d9cb86 100644 --- a/pandas/tests/window/test_win_type.py +++ b/pandas/tests/window/test_win_type.py @@ -15,6 +15,27 @@ from pandas.api.indexers import BaseIndexer +@pytest.fixture( + params=[ + "triang", + "blackman", + "hamming", + "bartlett", + "bohman", + "blackmanharris", + "nuttall", + "barthann", + ] +) +def win_types(request): + return request.param + + +@pytest.fixture(params=["kaiser", "gaussian", "general_gaussian", "exponential"]) +def win_types_special(request): + return request.param + + @td.skip_if_no_scipy def test_constructor(frame_or_series): # GH 12669