diff --git a/pandas/tests/extension/conftest.py b/pandas/tests/extension/conftest.py index 9e1b44d3bac02..7b7945b15ed83 100644 --- a/pandas/tests/extension/conftest.py +++ b/pandas/tests/extension/conftest.py @@ -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 @@ -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 diff --git a/pandas/tests/extension/decimal/test_decimal.py b/pandas/tests/extension/decimal/test_decimal.py index ed64a9939a203..87c23c13d91f9 100644 --- a/pandas/tests/extension/decimal/test_decimal.py +++ b/pandas/tests/extension/decimal/test_decimal.py @@ -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") diff --git a/pandas/tests/extension/json/test_json.py b/pandas/tests/extension/json/test_json.py index 4e341fa81dae8..9e1a4fb5da251 100644 --- a/pandas/tests/extension/json/test_json.py +++ b/pandas/tests/extension/json/test_json.py @@ -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 @@ -78,11 +73,6 @@ def data_for_grouping(): ) -@pytest.fixture -def data_for_twos(dtype): - pytest.skip("Not a numeric dtype") - - class BaseJSON: pass diff --git a/pandas/tests/extension/test_arrow.py b/pandas/tests/extension/test_arrow.py index c0f310fa49c41..03c12850b1d23 100644 --- a/pandas/tests/extension/test_arrow.py +++ b/pandas/tests/extension/test_arrow.py @@ -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 diff --git a/pandas/tests/extension/test_categorical.py b/pandas/tests/extension/test_categorical.py index c4c83b0df85fe..33e5c9ad72982 100644 --- a/pandas/tests/extension/test_categorical.py +++ b/pandas/tests/extension/test_categorical.py @@ -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"]) diff --git a/pandas/tests/extension/test_datetime.py b/pandas/tests/extension/test_datetime.py index 80e75824763b6..97773d0d40a57 100644 --- a/pandas/tests/extension/test_datetime.py +++ b/pandas/tests/extension/test_datetime.py @@ -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): @@ -86,11 +81,6 @@ def cmp(a, b): return cmp -@pytest.fixture -def na_value(): - return pd.NaT - - # ---------------------------------------------------------------------------- class BaseDatetimeTests: pass diff --git a/pandas/tests/extension/test_interval.py b/pandas/tests/extension/test_interval.py index d565f14fe199d..e085298ddf3dc 100644 --- a/pandas/tests/extension/test_interval.py +++ b/pandas/tests/extension/test_interval.py @@ -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) diff --git a/pandas/tests/extension/test_masked.py b/pandas/tests/extension/test_masked.py index dc4cea04420d9..c4195be8ea121 100644 --- a/pandas/tests/extension/test_masked.py +++ b/pandas/tests/extension/test_masked.py @@ -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": diff --git a/pandas/tests/extension/test_numpy.py b/pandas/tests/extension/test_numpy.py index 2d4641ff41729..a54729de57a97 100644 --- a/pandas/tests/extension/test_numpy.py +++ b/pandas/tests/extension/test_numpy.py @@ -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): diff --git a/pandas/tests/extension/test_period.py b/pandas/tests/extension/test_period.py index 5afbbe5214a5a..63297c20daa97 100644 --- a/pandas/tests/extension/test_period.py +++ b/pandas/tests/extension/test_period.py @@ -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 @@ -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) @@ -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 diff --git a/pandas/tests/extension/test_sparse.py b/pandas/tests/extension/test_sparse.py index 322b90095e2ac..852ae37bd34ae 100644 --- a/pandas/tests/extension/test_sparse.py +++ b/pandas/tests/extension/test_sparse.py @@ -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) diff --git a/pandas/tests/extension/test_string.py b/pandas/tests/extension/test_string.py index 34614bc983060..6597ff84e3ca4 100644 --- a/pandas/tests/extension/test_string.py +++ b/pandas/tests/extension/test_string.py @@ -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(