Skip to content

REF: simplify fixtures #54434

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 2 commits into from
Aug 6, 2023
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
13 changes: 9 additions & 4 deletions pandas/tests/extension/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,17 @@ def data():


@pytest.fixture
def data_for_twos():
def data_for_twos(dtype):
"""
Length-100 array in which all the elements are two.

Call pytest.skip in your fixture if the dtype does not support divmod.
"""
if not (dtype._is_numeric or dtype.kind == "m"):
# Object-dtypes may want to allow this, but for the most part
# only numeric and timedelta-like dtypes will need to implement this.
pytest.skip("Not a numeric dtype")

raise NotImplementedError


Expand Down Expand Up @@ -112,9 +117,9 @@ def na_cmp():


@pytest.fixture
def na_value():
"""The scalar missing value for this type. Default 'None'"""
return None
def na_value(dtype):
"""The scalar missing value for this type. Default dtype.na_value"""
return dtype.na_value


@pytest.fixture
Expand Down
5 changes: 0 additions & 5 deletions pandas/tests/extension/decimal/test_decimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@ def na_cmp():
return lambda x, y: x.is_nan() and y.is_nan()


@pytest.fixture
def na_value():
return decimal.Decimal("NaN")


@pytest.fixture
def data_for_grouping():
b = decimal.Decimal("1.0")
Expand Down
10 changes: 0 additions & 10 deletions pandas/tests/extension/json/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@ def data_missing_for_sorting():
return JSONArray([{"b": 1}, {}, {"a": 4}])


@pytest.fixture
def na_value(dtype):
return dtype.na_value


@pytest.fixture
def na_cmp():
return operator.eq
Expand All @@ -78,11 +73,6 @@ def data_for_grouping():
)


@pytest.fixture
def data_for_twos(dtype):
pytest.skip("Not a numeric dtype")


class BaseJSON:
pass

Expand Down
6 changes: 0 additions & 6 deletions pandas/tests/extension/test_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,6 @@ def data_for_twos(data):
# TODO: skip otherwise?


@pytest.fixture
def na_value():
"""The scalar missing value for this type. Default 'None'"""
return pd.NA


class TestBaseCasting(base.BaseCastingTests):
def test_astype_str(self, data, request):
pa_dtype = data.dtype.pyarrow_dtype
Expand Down
10 changes: 0 additions & 10 deletions pandas/tests/extension/test_categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,6 @@ def data_missing_for_sorting():
return Categorical(["A", None, "B"], categories=["B", "A"], ordered=True)


@pytest.fixture
def data_for_twos(dtype):
pytest.skip("Not a numeric dtype")


@pytest.fixture
def na_value():
return np.nan


@pytest.fixture
def data_for_grouping():
return Categorical(["a", "a", None, None, "b", "b", "a", "c"])
Expand Down
10 changes: 0 additions & 10 deletions pandas/tests/extension/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,6 @@ def data_for_grouping(dtype):
)


@pytest.fixture
def data_for_twos(dtype):
pytest.skip("Not a numeric dtype.")


@pytest.fixture
def na_cmp():
def cmp(a, b):
Expand All @@ -86,11 +81,6 @@ def cmp(a, b):
return cmp


@pytest.fixture
def na_value():
return pd.NaT


# ----------------------------------------------------------------------------
class BaseDatetimeTests:
pass
Expand Down
5 changes: 0 additions & 5 deletions pandas/tests/extension/test_interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ def data_missing_for_sorting():
return IntervalArray.from_tuples([(1, 2), None, (0, 1)])


@pytest.fixture
def na_value():
return np.nan


@pytest.fixture
def data_for_grouping():
a = (0, 1)
Expand Down
5 changes: 0 additions & 5 deletions pandas/tests/extension/test_masked.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,6 @@ def na_cmp():
return lambda x, y: x is pd.NA and y is pd.NA


@pytest.fixture
def na_value():
return pd.NA


@pytest.fixture
def data_for_grouping(dtype):
if dtype.kind == "f":
Expand Down
5 changes: 0 additions & 5 deletions pandas/tests/extension/test_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,6 @@ def data_missing(allow_in_pandas, dtype):
return NumpyExtensionArray(np.array([np.nan, 1.0]))


@pytest.fixture
def na_value():
return np.nan


@pytest.fixture
def na_cmp():
def cmp(a, b):
Expand Down
11 changes: 0 additions & 11 deletions pandas/tests/extension/test_period.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

from pandas.core.dtypes.dtypes import PeriodDtype

import pandas as pd
import pandas._testing as tm
from pandas.core.arrays import PeriodArray
from pandas.tests.extension import base
Expand All @@ -38,11 +37,6 @@ def data(dtype):
return PeriodArray(np.arange(1970, 2070), dtype=dtype)


@pytest.fixture
def data_for_twos(dtype):
pytest.skip("Not a numeric dtype")


@pytest.fixture
def data_for_sorting(dtype):
return PeriodArray([2018, 2019, 2017], dtype=dtype)
Expand All @@ -67,11 +61,6 @@ def data_for_grouping(dtype):
return PeriodArray([B, B, NA, NA, A, A, B, C], dtype=dtype)


@pytest.fixture
def na_value():
return pd.NaT


class BasePeriodTests:
pass

Expand Down
5 changes: 0 additions & 5 deletions pandas/tests/extension/test_sparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,6 @@ def data_missing_for_sorting(request):
return SparseArray([2, np.nan, 1], fill_value=request.param)


@pytest.fixture
def na_value():
return np.nan


@pytest.fixture
def na_cmp():
return lambda left, right: pd.isna(left) and pd.isna(right)
Expand Down
5 changes: 0 additions & 5 deletions pandas/tests/extension/test_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,6 @@ def data_missing_for_sorting(dtype, chunked):
return split_array(arr) if chunked else arr


@pytest.fixture
def na_value():
return pd.NA


@pytest.fixture
def data_for_grouping(dtype, chunked):
arr = dtype.construct_array_type()._from_sequence(
Expand Down