Skip to content

TST: Move once-used fixtures to specific files #45674

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 0 additions & 133 deletions pandas/tests/window/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
DataFrame,
Series,
bdate_range,
to_datetime,
)


Expand All @@ -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",
Expand All @@ -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
Expand All @@ -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"""
Expand Down Expand Up @@ -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."""
Expand Down
7 changes: 0 additions & 7 deletions pandas/tests/window/moments/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions pandas/tests/window/test_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
[
Expand Down
25 changes: 25 additions & 0 deletions pandas/tests/window/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)})
Expand Down
23 changes: 23 additions & 0 deletions pandas/tests/window/test_numba.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 33 additions & 0 deletions pandas/tests/window/test_pairwise.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
1 change: 1 addition & 0 deletions pandas/tests/window/test_rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/window/test_timeseries_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
Expand Down
21 changes: 21 additions & 0 deletions pandas/tests/window/test_win_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down