Skip to content

Commit c0663f8

Browse files
pratyushsharanfeefladder
authored andcommitted
TST: cleanup of any_* test fixtures GH38017 (pandas-dev#43047)
1 parent 0e6c804 commit c0663f8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+262
-248
lines changed

asv_bench/benchmarks/dtypes.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ def time_pandas_dtype_invalid(self, dtype):
5151
class SelectDtypes:
5252

5353
params = [
54-
tm.ALL_INT_DTYPES
55-
+ tm.ALL_EA_INT_DTYPES
56-
+ tm.FLOAT_DTYPES
54+
tm.ALL_INT_NUMPY_DTYPES
55+
+ tm.ALL_INT_EA_DTYPES
56+
+ tm.FLOAT_NUMPY_DTYPES
5757
+ tm.COMPLEX_DTYPES
5858
+ tm.DATETIME64_DTYPES
5959
+ tm.TIMEDELTA64_DTYPES

pandas/_testing/__init__.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,14 @@
123123
_N = 30
124124
_K = 4
125125

126-
UNSIGNED_INT_DTYPES: list[Dtype] = ["uint8", "uint16", "uint32", "uint64"]
127-
UNSIGNED_EA_INT_DTYPES: list[Dtype] = ["UInt8", "UInt16", "UInt32", "UInt64"]
128-
SIGNED_INT_DTYPES: list[Dtype] = [int, "int8", "int16", "int32", "int64"]
129-
SIGNED_EA_INT_DTYPES: list[Dtype] = ["Int8", "Int16", "Int32", "Int64"]
130-
ALL_INT_DTYPES = UNSIGNED_INT_DTYPES + SIGNED_INT_DTYPES
131-
ALL_EA_INT_DTYPES = UNSIGNED_EA_INT_DTYPES + SIGNED_EA_INT_DTYPES
132-
133-
FLOAT_DTYPES: list[Dtype] = [float, "float32", "float64"]
126+
UNSIGNED_INT_NUMPY_DTYPES: list[Dtype] = ["uint8", "uint16", "uint32", "uint64"]
127+
UNSIGNED_INT_EA_DTYPES: list[Dtype] = ["UInt8", "UInt16", "UInt32", "UInt64"]
128+
SIGNED_INT_NUMPY_DTYPES: list[Dtype] = [int, "int8", "int16", "int32", "int64"]
129+
SIGNED_INT_EA_DTYPES: list[Dtype] = ["Int8", "Int16", "Int32", "Int64"]
130+
ALL_INT_NUMPY_DTYPES = UNSIGNED_INT_NUMPY_DTYPES + SIGNED_INT_NUMPY_DTYPES
131+
ALL_INT_EA_DTYPES = UNSIGNED_INT_EA_DTYPES + SIGNED_INT_EA_DTYPES
132+
133+
FLOAT_NUMPY_DTYPES: list[Dtype] = [float, "float32", "float64"]
134134
FLOAT_EA_DTYPES: list[Dtype] = ["Float32", "Float64"]
135135
COMPLEX_DTYPES: list[Dtype] = [complex, "complex64", "complex128"]
136136
STRING_DTYPES: list[Dtype] = [str, "str", "U"]
@@ -142,9 +142,9 @@
142142
BYTES_DTYPES: list[Dtype] = [bytes, "bytes"]
143143
OBJECT_DTYPES: list[Dtype] = [object, "object"]
144144

145-
ALL_REAL_DTYPES = FLOAT_DTYPES + ALL_INT_DTYPES
145+
ALL_REAL_NUMPY_DTYPES = FLOAT_NUMPY_DTYPES + ALL_INT_NUMPY_DTYPES
146146
ALL_NUMPY_DTYPES = (
147-
ALL_REAL_DTYPES
147+
ALL_REAL_NUMPY_DTYPES
148148
+ COMPLEX_DTYPES
149149
+ STRING_DTYPES
150150
+ DATETIME64_DTYPES

pandas/conftest.py

+20-20
Original file line numberDiff line numberDiff line change
@@ -1232,8 +1232,8 @@ def timedelta64_dtype(request):
12321232
return request.param
12331233

12341234

1235-
@pytest.fixture(params=tm.FLOAT_DTYPES)
1236-
def float_dtype(request):
1235+
@pytest.fixture(params=tm.FLOAT_NUMPY_DTYPES)
1236+
def float_numpy_dtype(request):
12371237
"""
12381238
Parameterized fixture for float dtypes.
12391239
@@ -1255,8 +1255,8 @@ def float_ea_dtype(request):
12551255
return request.param
12561256

12571257

1258-
@pytest.fixture(params=tm.FLOAT_DTYPES + tm.FLOAT_EA_DTYPES)
1259-
def any_float_allowed_nullable_dtype(request):
1258+
@pytest.fixture(params=tm.FLOAT_NUMPY_DTYPES + tm.FLOAT_EA_DTYPES)
1259+
def any_float_dtype(request):
12601260
"""
12611261
Parameterized fixture for float dtypes.
12621262
@@ -1281,8 +1281,8 @@ def complex_dtype(request):
12811281
return request.param
12821282

12831283

1284-
@pytest.fixture(params=tm.SIGNED_INT_DTYPES)
1285-
def sint_dtype(request):
1284+
@pytest.fixture(params=tm.SIGNED_INT_NUMPY_DTYPES)
1285+
def any_signed_int_numpy_dtype(request):
12861286
"""
12871287
Parameterized fixture for signed integer dtypes.
12881288
@@ -1295,8 +1295,8 @@ def sint_dtype(request):
12951295
return request.param
12961296

12971297

1298-
@pytest.fixture(params=tm.UNSIGNED_INT_DTYPES)
1299-
def uint_dtype(request):
1298+
@pytest.fixture(params=tm.UNSIGNED_INT_NUMPY_DTYPES)
1299+
def any_unsigned_int_numpy_dtype(request):
13001300
"""
13011301
Parameterized fixture for unsigned integer dtypes.
13021302
@@ -1308,8 +1308,8 @@ def uint_dtype(request):
13081308
return request.param
13091309

13101310

1311-
@pytest.fixture(params=tm.ALL_INT_DTYPES)
1312-
def any_int_dtype(request):
1311+
@pytest.fixture(params=tm.ALL_INT_NUMPY_DTYPES)
1312+
def any_int_numpy_dtype(request):
13131313
"""
13141314
Parameterized fixture for any integer dtype.
13151315
@@ -1326,8 +1326,8 @@ def any_int_dtype(request):
13261326
return request.param
13271327

13281328

1329-
@pytest.fixture(params=tm.ALL_EA_INT_DTYPES)
1330-
def any_nullable_int_dtype(request):
1329+
@pytest.fixture(params=tm.ALL_INT_EA_DTYPES)
1330+
def any_int_ea_dtype(request):
13311331
"""
13321332
Parameterized fixture for any nullable integer dtype.
13331333
@@ -1343,8 +1343,8 @@ def any_nullable_int_dtype(request):
13431343
return request.param
13441344

13451345

1346-
@pytest.fixture(params=tm.ALL_INT_DTYPES + tm.ALL_EA_INT_DTYPES)
1347-
def any_int_or_nullable_int_dtype(request):
1346+
@pytest.fixture(params=tm.ALL_INT_NUMPY_DTYPES + tm.ALL_INT_EA_DTYPES)
1347+
def any_int_dtype(request):
13481348
"""
13491349
Parameterized fixture for any nullable integer dtype.
13501350
@@ -1369,8 +1369,8 @@ def any_int_or_nullable_int_dtype(request):
13691369
return request.param
13701370

13711371

1372-
@pytest.fixture(params=tm.ALL_EA_INT_DTYPES + tm.FLOAT_EA_DTYPES)
1373-
def any_nullable_numeric_dtype(request):
1372+
@pytest.fixture(params=tm.ALL_INT_EA_DTYPES + tm.FLOAT_EA_DTYPES)
1373+
def any_numeric_ea_dtype(request):
13741374
"""
13751375
Parameterized fixture for any nullable integer dtype and
13761376
any float ea dtypes.
@@ -1389,8 +1389,8 @@ def any_nullable_numeric_dtype(request):
13891389
return request.param
13901390

13911391

1392-
@pytest.fixture(params=tm.SIGNED_EA_INT_DTYPES)
1393-
def any_signed_nullable_int_dtype(request):
1392+
@pytest.fixture(params=tm.SIGNED_INT_EA_DTYPES)
1393+
def any_signed_int_ea_dtype(request):
13941394
"""
13951395
Parameterized fixture for any signed nullable integer dtype.
13961396
@@ -1402,8 +1402,8 @@ def any_signed_nullable_int_dtype(request):
14021402
return request.param
14031403

14041404

1405-
@pytest.fixture(params=tm.ALL_REAL_DTYPES)
1406-
def any_real_dtype(request):
1405+
@pytest.fixture(params=tm.ALL_REAL_NUMPY_DTYPES)
1406+
def any_real_numpy_dtype(request):
14071407
"""
14081408
Parameterized fixture for any (purely) real numeric dtype.
14091409

pandas/tests/arithmetic/test_numeric.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,14 @@ def test_div_negative_zero(self, zero, numeric_idx, op):
391391
# ------------------------------------------------------------------
392392

393393
@pytest.mark.parametrize("dtype1", [np.int64, np.float64, np.uint64])
394-
def test_ser_div_ser(self, switch_numexpr_min_elements, dtype1, any_real_dtype):
394+
def test_ser_div_ser(
395+
self,
396+
switch_numexpr_min_elements,
397+
dtype1,
398+
any_real_numpy_dtype,
399+
):
395400
# no longer do integer div for any ops, but deal with the 0's
396-
dtype2 = any_real_dtype
401+
dtype2 = any_real_numpy_dtype
397402

398403
first = Series([3, 4, 5, 8], name="first").astype(dtype1)
399404
second = Series([0, 0, 0, 3], name="second").astype(dtype2)
@@ -416,9 +421,9 @@ def test_ser_div_ser(self, switch_numexpr_min_elements, dtype1, any_real_dtype):
416421
assert not result.equals(second / first)
417422

418423
@pytest.mark.parametrize("dtype1", [np.int64, np.float64, np.uint64])
419-
def test_ser_divmod_zero(self, dtype1, any_real_dtype):
424+
def test_ser_divmod_zero(self, dtype1, any_real_numpy_dtype):
420425
# GH#26987
421-
dtype2 = any_real_dtype
426+
dtype2 = any_real_numpy_dtype
422427
left = Series([1, 1]).astype(dtype1)
423428
right = Series([0, 2]).astype(dtype2)
424429

pandas/tests/arithmetic/test_timedelta64.py

+11-6
Original file line numberDiff line numberDiff line change
@@ -1142,12 +1142,12 @@ def test_td64arr_addsub_numeric_scalar_invalid(self, box_with_array, other):
11421142
ids=lambda x: type(x).__name__,
11431143
)
11441144
def test_td64arr_addsub_numeric_arr_invalid(
1145-
self, box_with_array, vec, any_real_dtype
1145+
self, box_with_array, vec, any_real_numpy_dtype
11461146
):
11471147
tdser = Series(["59 Days", "59 Days", "NaT"], dtype="m8[ns]")
11481148
tdarr = tm.box_expected(tdser, box_with_array)
11491149

1150-
vector = vec.astype(any_real_dtype)
1150+
vector = vec.astype(any_real_numpy_dtype)
11511151
assert_invalid_addsub_type(tdarr, vector)
11521152

11531153
def test_td64arr_add_sub_int(self, box_with_array, one):
@@ -2027,13 +2027,18 @@ def test_td64arr_div_numeric_scalar(self, box_with_array, two):
20272027
[np.array([20, 30, 40]), pd.Index([20, 30, 40]), Series([20, 30, 40])],
20282028
ids=lambda x: type(x).__name__,
20292029
)
2030-
def test_td64arr_rmul_numeric_array(self, box_with_array, vector, any_real_dtype):
2030+
def test_td64arr_rmul_numeric_array(
2031+
self,
2032+
box_with_array,
2033+
vector,
2034+
any_real_numpy_dtype,
2035+
):
20312036
# GH#4521
20322037
# divide/multiply by integers
20332038
xbox = get_upcast_box(box_with_array, vector)
20342039

20352040
tdser = Series(["59 Days", "59 Days", "NaT"], dtype="m8[ns]")
2036-
vector = vector.astype(any_real_dtype)
2041+
vector = vector.astype(any_real_numpy_dtype)
20372042

20382043
expected = Series(["1180 Days", "1770 Days", "NaT"], dtype="timedelta64[ns]")
20392044

@@ -2052,14 +2057,14 @@ def test_td64arr_rmul_numeric_array(self, box_with_array, vector, any_real_dtype
20522057
ids=lambda x: type(x).__name__,
20532058
)
20542059
def test_td64arr_div_numeric_array(
2055-
self, box_with_array, vector, any_real_dtype, using_array_manager
2060+
self, box_with_array, vector, any_real_numpy_dtype, using_array_manager
20562061
):
20572062
# GH#4521
20582063
# divide/multiply by integers
20592064
xbox = get_upcast_box(box_with_array, vector)
20602065

20612066
tdser = Series(["59 Days", "59 Days", "NaT"], dtype="m8[ns]")
2062-
vector = vector.astype(any_real_dtype)
2067+
vector = vector.astype(any_real_numpy_dtype)
20632068

20642069
expected = Series(["2.95D", "1D 23H 12m", "NaT"], dtype="timedelta64[ns]")
20652070

pandas/tests/arrays/integer/test_arithmetic.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,8 @@ def test_reduce_to_float(op):
291291
([-1, 0, 1], [1, 0, -1], [1, 0, 1]),
292292
],
293293
)
294-
def test_unary_int_operators(
295-
any_signed_nullable_int_dtype, source, neg_target, abs_target
296-
):
297-
dtype = any_signed_nullable_int_dtype
294+
def test_unary_int_operators(any_signed_int_ea_dtype, source, neg_target, abs_target):
295+
dtype = any_signed_int_ea_dtype
298296
arr = pd.array(source, dtype=dtype)
299297
neg_result, pos_result, abs_result = -arr, +arr, abs(arr)
300298
neg_target = pd.array(neg_target, dtype=dtype)

pandas/tests/arrays/integer/test_comparison.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,17 @@ def test_no_shared_mask(self, data):
8383
result = data + 1
8484
assert np.shares_memory(result._mask, data._mask) is False
8585

86-
def test_compare_to_string(self, any_nullable_int_dtype):
86+
def test_compare_to_string(self, any_int_ea_dtype):
8787
# GH 28930
88-
s = pd.Series([1, None], dtype=any_nullable_int_dtype)
88+
s = pd.Series([1, None], dtype=any_int_ea_dtype)
8989
result = s == "a"
9090
expected = pd.Series([False, pd.NA], dtype="boolean")
9191

9292
self.assert_series_equal(result, expected)
9393

94-
def test_compare_to_int(self, any_nullable_int_dtype, all_compare_operators):
94+
def test_compare_to_int(self, any_int_ea_dtype, all_compare_operators):
9595
# GH 28930
96-
s1 = pd.Series([1, None, 3], dtype=any_nullable_int_dtype)
96+
s1 = pd.Series([1, None, 3], dtype=any_int_ea_dtype)
9797
s2 = pd.Series([1, None, 3], dtype="float")
9898

9999
method = getattr(s1, all_compare_operators)

pandas/tests/arrays/integer/test_function.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ def test_value_counts_with_normalize():
136136

137137
@pytest.mark.parametrize("skipna", [True, False])
138138
@pytest.mark.parametrize("min_count", [0, 4])
139-
def test_integer_array_sum(skipna, min_count, any_nullable_int_dtype):
140-
dtype = any_nullable_int_dtype
139+
def test_integer_array_sum(skipna, min_count, any_int_ea_dtype):
140+
dtype = any_int_ea_dtype
141141
arr = pd.array([1, 2, 3, None], dtype=dtype)
142142
result = arr.sum(skipna=skipna, min_count=min_count)
143143
if skipna and min_count == 0:
@@ -148,8 +148,8 @@ def test_integer_array_sum(skipna, min_count, any_nullable_int_dtype):
148148

149149
@pytest.mark.parametrize("skipna", [True, False])
150150
@pytest.mark.parametrize("method", ["min", "max"])
151-
def test_integer_array_min_max(skipna, method, any_nullable_int_dtype):
152-
dtype = any_nullable_int_dtype
151+
def test_integer_array_min_max(skipna, method, any_int_ea_dtype):
152+
dtype = any_int_ea_dtype
153153
arr = pd.array([0, 1, None], dtype=dtype)
154154
func = getattr(arr, method)
155155
result = func(skipna=skipna)
@@ -161,8 +161,8 @@ def test_integer_array_min_max(skipna, method, any_nullable_int_dtype):
161161

162162
@pytest.mark.parametrize("skipna", [True, False])
163163
@pytest.mark.parametrize("min_count", [0, 9])
164-
def test_integer_array_prod(skipna, min_count, any_nullable_int_dtype):
165-
dtype = any_nullable_int_dtype
164+
def test_integer_array_prod(skipna, min_count, any_int_ea_dtype):
165+
dtype = any_int_ea_dtype
166166
arr = pd.array([1, 2, None], dtype=dtype)
167167
result = arr.prod(skipna=skipna, min_count=min_count)
168168
if skipna and min_count == 0:

pandas/tests/arrays/masked/test_arithmetic.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from pandas.core.arrays import ExtensionArray
1111

1212
# integer dtypes
13-
arrays = [pd.array([1, 2, 3, None], dtype=dtype) for dtype in tm.ALL_EA_INT_DTYPES]
13+
arrays = [pd.array([1, 2, 3, None], dtype=dtype) for dtype in tm.ALL_INT_EA_DTYPES]
1414
scalars: list[Any] = [2] * len(arrays)
1515
# floating dtypes
1616
arrays += [pd.array([0.1, 0.2, 0.3, None], dtype=dtype) for dtype in tm.FLOAT_EA_DTYPES]

pandas/tests/arrays/masked/test_arrow_compat.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from pandas.core.arrays._arrow_utils import pyarrow_array_to_numpy_and_mask
1212

13-
arrays = [pd.array([1, 2, 3, None], dtype=dtype) for dtype in tm.ALL_EA_INT_DTYPES]
13+
arrays = [pd.array([1, 2, 3, None], dtype=dtype) for dtype in tm.ALL_INT_EA_DTYPES]
1414
arrays += [pd.array([0.1, 0.2, 0.3, None], dtype=dtype) for dtype in tm.FLOAT_EA_DTYPES]
1515
arrays += [pd.array([True, False, True, None], dtype="boolean")]
1616

@@ -85,8 +85,8 @@ def test_arrow_sliced(data):
8585

8686

8787
@pytest.fixture
88-
def np_dtype_to_arrays(any_real_dtype):
89-
np_dtype = np.dtype(any_real_dtype)
88+
def np_dtype_to_arrays(any_real_numpy_dtype):
89+
np_dtype = np.dtype(any_real_numpy_dtype)
9090
pa_type = pa.from_numpy_dtype(np_dtype)
9191

9292
# None ensures the creation of a bitmask buffer.

pandas/tests/arrays/masked/test_function.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import pandas as pd
77
import pandas._testing as tm
88

9-
arrays = [pd.array([1, 2, 3, None], dtype=dtype) for dtype in tm.ALL_EA_INT_DTYPES]
9+
arrays = [pd.array([1, 2, 3, None], dtype=dtype) for dtype in tm.ALL_INT_EA_DTYPES]
1010
arrays += [
1111
pd.array([0.141, -0.268, 5.895, None], dtype=dtype) for dtype in tm.FLOAT_EA_DTYPES
1212
]

pandas/tests/arrays/sparse/test_array.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -511,10 +511,10 @@ def test_astype_bool(self):
511511
)
512512
tm.assert_sp_array_equal(result, expected)
513513

514-
def test_astype_all(self, any_real_dtype):
514+
def test_astype_all(self, any_real_numpy_dtype):
515515
vals = np.array([1, 2, 3])
516516
arr = SparseArray(vals, fill_value=1)
517-
typ = np.dtype(any_real_dtype)
517+
typ = np.dtype(any_real_numpy_dtype)
518518
res = arr.astype(typ)
519519
assert res.dtype == SparseDtype(typ, 1)
520520
assert res.sp_values.dtype == typ

pandas/tests/arrays/string_/test_string.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -324,11 +324,11 @@ def test_astype_nullable_int(dtype):
324324
tm.assert_extension_array_equal(result, expected)
325325

326326

327-
def test_astype_float(dtype, any_float_allowed_nullable_dtype):
327+
def test_astype_float(dtype, any_float_dtype):
328328
# Don't compare arrays (37974)
329329
ser = pd.Series(["1.1", pd.NA, "3.3"], dtype=dtype)
330-
result = ser.astype(any_float_allowed_nullable_dtype)
331-
expected = pd.Series([1.1, np.nan, 3.3], dtype=any_float_allowed_nullable_dtype)
330+
result = ser.astype(any_float_dtype)
331+
expected = pd.Series([1.1, np.nan, 3.3], dtype=any_float_dtype)
332332
tm.assert_series_equal(result, expected)
333333

334334

0 commit comments

Comments
 (0)