Skip to content

Commit 6704f6b

Browse files
authored
REF: simplify fixtures (#54434)
1 parent 24c0c1a commit 6704f6b

12 files changed

+9
-81
lines changed

pandas/tests/extension/conftest.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,17 @@ def data():
2626

2727

2828
@pytest.fixture
29-
def data_for_twos():
29+
def data_for_twos(dtype):
3030
"""
3131
Length-100 array in which all the elements are two.
3232
3333
Call pytest.skip in your fixture if the dtype does not support divmod.
3434
"""
35+
if not (dtype._is_numeric or dtype.kind == "m"):
36+
# Object-dtypes may want to allow this, but for the most part
37+
# only numeric and timedelta-like dtypes will need to implement this.
38+
pytest.skip("Not a numeric dtype")
39+
3540
raise NotImplementedError
3641

3742

@@ -112,9 +117,9 @@ def na_cmp():
112117

113118

114119
@pytest.fixture
115-
def na_value():
116-
"""The scalar missing value for this type. Default 'None'"""
117-
return None
120+
def na_value(dtype):
121+
"""The scalar missing value for this type. Default dtype.na_value"""
122+
return dtype.na_value
118123

119124

120125
@pytest.fixture

pandas/tests/extension/decimal/test_decimal.py

-5
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,6 @@ def na_cmp():
5656
return lambda x, y: x.is_nan() and y.is_nan()
5757

5858

59-
@pytest.fixture
60-
def na_value():
61-
return decimal.Decimal("NaN")
62-
63-
6459
@pytest.fixture
6560
def data_for_grouping():
6661
b = decimal.Decimal("1.0")

pandas/tests/extension/json/test_json.py

-10
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,6 @@ def data_missing_for_sorting():
5252
return JSONArray([{"b": 1}, {}, {"a": 4}])
5353

5454

55-
@pytest.fixture
56-
def na_value(dtype):
57-
return dtype.na_value
58-
59-
6055
@pytest.fixture
6156
def na_cmp():
6257
return operator.eq
@@ -78,11 +73,6 @@ def data_for_grouping():
7873
)
7974

8075

81-
@pytest.fixture
82-
def data_for_twos(dtype):
83-
pytest.skip("Not a numeric dtype")
84-
85-
8676
class BaseJSON:
8777
pass
8878

pandas/tests/extension/test_arrow.py

-6
Original file line numberDiff line numberDiff line change
@@ -265,12 +265,6 @@ def data_for_twos(data):
265265
# TODO: skip otherwise?
266266

267267

268-
@pytest.fixture
269-
def na_value():
270-
"""The scalar missing value for this type. Default 'None'"""
271-
return pd.NA
272-
273-
274268
class TestBaseCasting(base.BaseCastingTests):
275269
def test_astype_str(self, data, request):
276270
pa_dtype = data.dtype.pyarrow_dtype

pandas/tests/extension/test_categorical.py

-10
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,6 @@ def data_missing_for_sorting():
6767
return Categorical(["A", None, "B"], categories=["B", "A"], ordered=True)
6868

6969

70-
@pytest.fixture
71-
def data_for_twos(dtype):
72-
pytest.skip("Not a numeric dtype")
73-
74-
75-
@pytest.fixture
76-
def na_value():
77-
return np.nan
78-
79-
8070
@pytest.fixture
8171
def data_for_grouping():
8272
return Categorical(["a", "a", None, None, "b", "b", "a", "c"])

pandas/tests/extension/test_datetime.py

-10
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,6 @@ def data_for_grouping(dtype):
7373
)
7474

7575

76-
@pytest.fixture
77-
def data_for_twos(dtype):
78-
pytest.skip("Not a numeric dtype.")
79-
80-
8176
@pytest.fixture
8277
def na_cmp():
8378
def cmp(a, b):
@@ -86,11 +81,6 @@ def cmp(a, b):
8681
return cmp
8782

8883

89-
@pytest.fixture
90-
def na_value():
91-
return pd.NaT
92-
93-
9484
# ----------------------------------------------------------------------------
9585
class BaseDatetimeTests:
9686
pass

pandas/tests/extension/test_interval.py

-5
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,6 @@ def data_missing_for_sorting():
5757
return IntervalArray.from_tuples([(1, 2), None, (0, 1)])
5858

5959

60-
@pytest.fixture
61-
def na_value():
62-
return np.nan
63-
64-
6560
@pytest.fixture
6661
def data_for_grouping():
6762
a = (0, 1)

pandas/tests/extension/test_masked.py

-5
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,6 @@ def na_cmp():
140140
return lambda x, y: x is pd.NA and y is pd.NA
141141

142142

143-
@pytest.fixture
144-
def na_value():
145-
return pd.NA
146-
147-
148143
@pytest.fixture
149144
def data_for_grouping(dtype):
150145
if dtype.kind == "f":

pandas/tests/extension/test_numpy.py

-5
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,6 @@ def data_missing(allow_in_pandas, dtype):
9797
return NumpyExtensionArray(np.array([np.nan, 1.0]))
9898

9999

100-
@pytest.fixture
101-
def na_value():
102-
return np.nan
103-
104-
105100
@pytest.fixture
106101
def na_cmp():
107102
def cmp(a, b):

pandas/tests/extension/test_period.py

-11
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
from pandas.core.dtypes.dtypes import PeriodDtype
2424

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

4039

41-
@pytest.fixture
42-
def data_for_twos(dtype):
43-
pytest.skip("Not a numeric dtype")
44-
45-
4640
@pytest.fixture
4741
def data_for_sorting(dtype):
4842
return PeriodArray([2018, 2019, 2017], dtype=dtype)
@@ -67,11 +61,6 @@ def data_for_grouping(dtype):
6761
return PeriodArray([B, B, NA, NA, A, A, B, C], dtype=dtype)
6862

6963

70-
@pytest.fixture
71-
def na_value():
72-
return pd.NaT
73-
74-
7564
class BasePeriodTests:
7665
pass
7766

pandas/tests/extension/test_sparse.py

-5
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,6 @@ def data_missing_for_sorting(request):
8383
return SparseArray([2, np.nan, 1], fill_value=request.param)
8484

8585

86-
@pytest.fixture
87-
def na_value():
88-
return np.nan
89-
90-
9186
@pytest.fixture
9287
def na_cmp():
9388
return lambda left, right: pd.isna(left) and pd.isna(right)

pandas/tests/extension/test_string.py

-5
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,6 @@ def data_missing_for_sorting(dtype, chunked):
8383
return split_array(arr) if chunked else arr
8484

8585

86-
@pytest.fixture
87-
def na_value():
88-
return pd.NA
89-
90-
9186
@pytest.fixture
9287
def data_for_grouping(dtype, chunked):
9388
arr = dtype.construct_array_type()._from_sequence(

0 commit comments

Comments
 (0)