Skip to content

Commit

Permalink
TST: cleanup of any_* test fixtures GH38017 (pandas-dev#43047)
Browse files Browse the repository at this point in the history
  • Loading branch information
pratyushsharan authored and feefladder committed Sep 7, 2021
1 parent 0e6c804 commit c0663f8
Show file tree
Hide file tree
Showing 45 changed files with 262 additions and 248 deletions.
6 changes: 3 additions & 3 deletions asv_bench/benchmarks/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ def time_pandas_dtype_invalid(self, dtype):
class SelectDtypes:

params = [
tm.ALL_INT_DTYPES
+ tm.ALL_EA_INT_DTYPES
+ tm.FLOAT_DTYPES
tm.ALL_INT_NUMPY_DTYPES
+ tm.ALL_INT_EA_DTYPES
+ tm.FLOAT_NUMPY_DTYPES
+ tm.COMPLEX_DTYPES
+ tm.DATETIME64_DTYPES
+ tm.TIMEDELTA64_DTYPES
Expand Down
20 changes: 10 additions & 10 deletions pandas/_testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,14 @@
_N = 30
_K = 4

UNSIGNED_INT_DTYPES: list[Dtype] = ["uint8", "uint16", "uint32", "uint64"]
UNSIGNED_EA_INT_DTYPES: list[Dtype] = ["UInt8", "UInt16", "UInt32", "UInt64"]
SIGNED_INT_DTYPES: list[Dtype] = [int, "int8", "int16", "int32", "int64"]
SIGNED_EA_INT_DTYPES: list[Dtype] = ["Int8", "Int16", "Int32", "Int64"]
ALL_INT_DTYPES = UNSIGNED_INT_DTYPES + SIGNED_INT_DTYPES
ALL_EA_INT_DTYPES = UNSIGNED_EA_INT_DTYPES + SIGNED_EA_INT_DTYPES

FLOAT_DTYPES: list[Dtype] = [float, "float32", "float64"]
UNSIGNED_INT_NUMPY_DTYPES: list[Dtype] = ["uint8", "uint16", "uint32", "uint64"]
UNSIGNED_INT_EA_DTYPES: list[Dtype] = ["UInt8", "UInt16", "UInt32", "UInt64"]
SIGNED_INT_NUMPY_DTYPES: list[Dtype] = [int, "int8", "int16", "int32", "int64"]
SIGNED_INT_EA_DTYPES: list[Dtype] = ["Int8", "Int16", "Int32", "Int64"]
ALL_INT_NUMPY_DTYPES = UNSIGNED_INT_NUMPY_DTYPES + SIGNED_INT_NUMPY_DTYPES
ALL_INT_EA_DTYPES = UNSIGNED_INT_EA_DTYPES + SIGNED_INT_EA_DTYPES

FLOAT_NUMPY_DTYPES: list[Dtype] = [float, "float32", "float64"]
FLOAT_EA_DTYPES: list[Dtype] = ["Float32", "Float64"]
COMPLEX_DTYPES: list[Dtype] = [complex, "complex64", "complex128"]
STRING_DTYPES: list[Dtype] = [str, "str", "U"]
Expand All @@ -142,9 +142,9 @@
BYTES_DTYPES: list[Dtype] = [bytes, "bytes"]
OBJECT_DTYPES: list[Dtype] = [object, "object"]

ALL_REAL_DTYPES = FLOAT_DTYPES + ALL_INT_DTYPES
ALL_REAL_NUMPY_DTYPES = FLOAT_NUMPY_DTYPES + ALL_INT_NUMPY_DTYPES
ALL_NUMPY_DTYPES = (
ALL_REAL_DTYPES
ALL_REAL_NUMPY_DTYPES
+ COMPLEX_DTYPES
+ STRING_DTYPES
+ DATETIME64_DTYPES
Expand Down
40 changes: 20 additions & 20 deletions pandas/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1232,8 +1232,8 @@ def timedelta64_dtype(request):
return request.param


@pytest.fixture(params=tm.FLOAT_DTYPES)
def float_dtype(request):
@pytest.fixture(params=tm.FLOAT_NUMPY_DTYPES)
def float_numpy_dtype(request):
"""
Parameterized fixture for float dtypes.
Expand All @@ -1255,8 +1255,8 @@ def float_ea_dtype(request):
return request.param


@pytest.fixture(params=tm.FLOAT_DTYPES + tm.FLOAT_EA_DTYPES)
def any_float_allowed_nullable_dtype(request):
@pytest.fixture(params=tm.FLOAT_NUMPY_DTYPES + tm.FLOAT_EA_DTYPES)
def any_float_dtype(request):
"""
Parameterized fixture for float dtypes.
Expand All @@ -1281,8 +1281,8 @@ def complex_dtype(request):
return request.param


@pytest.fixture(params=tm.SIGNED_INT_DTYPES)
def sint_dtype(request):
@pytest.fixture(params=tm.SIGNED_INT_NUMPY_DTYPES)
def any_signed_int_numpy_dtype(request):
"""
Parameterized fixture for signed integer dtypes.
Expand All @@ -1295,8 +1295,8 @@ def sint_dtype(request):
return request.param


@pytest.fixture(params=tm.UNSIGNED_INT_DTYPES)
def uint_dtype(request):
@pytest.fixture(params=tm.UNSIGNED_INT_NUMPY_DTYPES)
def any_unsigned_int_numpy_dtype(request):
"""
Parameterized fixture for unsigned integer dtypes.
Expand All @@ -1308,8 +1308,8 @@ def uint_dtype(request):
return request.param


@pytest.fixture(params=tm.ALL_INT_DTYPES)
def any_int_dtype(request):
@pytest.fixture(params=tm.ALL_INT_NUMPY_DTYPES)
def any_int_numpy_dtype(request):
"""
Parameterized fixture for any integer dtype.
Expand All @@ -1326,8 +1326,8 @@ def any_int_dtype(request):
return request.param


@pytest.fixture(params=tm.ALL_EA_INT_DTYPES)
def any_nullable_int_dtype(request):
@pytest.fixture(params=tm.ALL_INT_EA_DTYPES)
def any_int_ea_dtype(request):
"""
Parameterized fixture for any nullable integer dtype.
Expand All @@ -1343,8 +1343,8 @@ def any_nullable_int_dtype(request):
return request.param


@pytest.fixture(params=tm.ALL_INT_DTYPES + tm.ALL_EA_INT_DTYPES)
def any_int_or_nullable_int_dtype(request):
@pytest.fixture(params=tm.ALL_INT_NUMPY_DTYPES + tm.ALL_INT_EA_DTYPES)
def any_int_dtype(request):
"""
Parameterized fixture for any nullable integer dtype.
Expand All @@ -1369,8 +1369,8 @@ def any_int_or_nullable_int_dtype(request):
return request.param


@pytest.fixture(params=tm.ALL_EA_INT_DTYPES + tm.FLOAT_EA_DTYPES)
def any_nullable_numeric_dtype(request):
@pytest.fixture(params=tm.ALL_INT_EA_DTYPES + tm.FLOAT_EA_DTYPES)
def any_numeric_ea_dtype(request):
"""
Parameterized fixture for any nullable integer dtype and
any float ea dtypes.
Expand All @@ -1389,8 +1389,8 @@ def any_nullable_numeric_dtype(request):
return request.param


@pytest.fixture(params=tm.SIGNED_EA_INT_DTYPES)
def any_signed_nullable_int_dtype(request):
@pytest.fixture(params=tm.SIGNED_INT_EA_DTYPES)
def any_signed_int_ea_dtype(request):
"""
Parameterized fixture for any signed nullable integer dtype.
Expand All @@ -1402,8 +1402,8 @@ def any_signed_nullable_int_dtype(request):
return request.param


@pytest.fixture(params=tm.ALL_REAL_DTYPES)
def any_real_dtype(request):
@pytest.fixture(params=tm.ALL_REAL_NUMPY_DTYPES)
def any_real_numpy_dtype(request):
"""
Parameterized fixture for any (purely) real numeric dtype.
Expand Down
13 changes: 9 additions & 4 deletions pandas/tests/arithmetic/test_numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,14 @@ def test_div_negative_zero(self, zero, numeric_idx, op):
# ------------------------------------------------------------------

@pytest.mark.parametrize("dtype1", [np.int64, np.float64, np.uint64])
def test_ser_div_ser(self, switch_numexpr_min_elements, dtype1, any_real_dtype):
def test_ser_div_ser(
self,
switch_numexpr_min_elements,
dtype1,
any_real_numpy_dtype,
):
# no longer do integer div for any ops, but deal with the 0's
dtype2 = any_real_dtype
dtype2 = any_real_numpy_dtype

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

@pytest.mark.parametrize("dtype1", [np.int64, np.float64, np.uint64])
def test_ser_divmod_zero(self, dtype1, any_real_dtype):
def test_ser_divmod_zero(self, dtype1, any_real_numpy_dtype):
# GH#26987
dtype2 = any_real_dtype
dtype2 = any_real_numpy_dtype
left = Series([1, 1]).astype(dtype1)
right = Series([0, 2]).astype(dtype2)

Expand Down
17 changes: 11 additions & 6 deletions pandas/tests/arithmetic/test_timedelta64.py
Original file line number Diff line number Diff line change
Expand Up @@ -1142,12 +1142,12 @@ def test_td64arr_addsub_numeric_scalar_invalid(self, box_with_array, other):
ids=lambda x: type(x).__name__,
)
def test_td64arr_addsub_numeric_arr_invalid(
self, box_with_array, vec, any_real_dtype
self, box_with_array, vec, any_real_numpy_dtype
):
tdser = Series(["59 Days", "59 Days", "NaT"], dtype="m8[ns]")
tdarr = tm.box_expected(tdser, box_with_array)

vector = vec.astype(any_real_dtype)
vector = vec.astype(any_real_numpy_dtype)
assert_invalid_addsub_type(tdarr, vector)

def test_td64arr_add_sub_int(self, box_with_array, one):
Expand Down Expand Up @@ -2027,13 +2027,18 @@ def test_td64arr_div_numeric_scalar(self, box_with_array, two):
[np.array([20, 30, 40]), pd.Index([20, 30, 40]), Series([20, 30, 40])],
ids=lambda x: type(x).__name__,
)
def test_td64arr_rmul_numeric_array(self, box_with_array, vector, any_real_dtype):
def test_td64arr_rmul_numeric_array(
self,
box_with_array,
vector,
any_real_numpy_dtype,
):
# GH#4521
# divide/multiply by integers
xbox = get_upcast_box(box_with_array, vector)

tdser = Series(["59 Days", "59 Days", "NaT"], dtype="m8[ns]")
vector = vector.astype(any_real_dtype)
vector = vector.astype(any_real_numpy_dtype)

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

Expand All @@ -2052,14 +2057,14 @@ def test_td64arr_rmul_numeric_array(self, box_with_array, vector, any_real_dtype
ids=lambda x: type(x).__name__,
)
def test_td64arr_div_numeric_array(
self, box_with_array, vector, any_real_dtype, using_array_manager
self, box_with_array, vector, any_real_numpy_dtype, using_array_manager
):
# GH#4521
# divide/multiply by integers
xbox = get_upcast_box(box_with_array, vector)

tdser = Series(["59 Days", "59 Days", "NaT"], dtype="m8[ns]")
vector = vector.astype(any_real_dtype)
vector = vector.astype(any_real_numpy_dtype)

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

Expand Down
6 changes: 2 additions & 4 deletions pandas/tests/arrays/integer/test_arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,8 @@ def test_reduce_to_float(op):
([-1, 0, 1], [1, 0, -1], [1, 0, 1]),
],
)
def test_unary_int_operators(
any_signed_nullable_int_dtype, source, neg_target, abs_target
):
dtype = any_signed_nullable_int_dtype
def test_unary_int_operators(any_signed_int_ea_dtype, source, neg_target, abs_target):
dtype = any_signed_int_ea_dtype
arr = pd.array(source, dtype=dtype)
neg_result, pos_result, abs_result = -arr, +arr, abs(arr)
neg_target = pd.array(neg_target, dtype=dtype)
Expand Down
8 changes: 4 additions & 4 deletions pandas/tests/arrays/integer/test_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,17 @@ def test_no_shared_mask(self, data):
result = data + 1
assert np.shares_memory(result._mask, data._mask) is False

def test_compare_to_string(self, any_nullable_int_dtype):
def test_compare_to_string(self, any_int_ea_dtype):
# GH 28930
s = pd.Series([1, None], dtype=any_nullable_int_dtype)
s = pd.Series([1, None], dtype=any_int_ea_dtype)
result = s == "a"
expected = pd.Series([False, pd.NA], dtype="boolean")

self.assert_series_equal(result, expected)

def test_compare_to_int(self, any_nullable_int_dtype, all_compare_operators):
def test_compare_to_int(self, any_int_ea_dtype, all_compare_operators):
# GH 28930
s1 = pd.Series([1, None, 3], dtype=any_nullable_int_dtype)
s1 = pd.Series([1, None, 3], dtype=any_int_ea_dtype)
s2 = pd.Series([1, None, 3], dtype="float")

method = getattr(s1, all_compare_operators)
Expand Down
12 changes: 6 additions & 6 deletions pandas/tests/arrays/integer/test_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ def test_value_counts_with_normalize():

@pytest.mark.parametrize("skipna", [True, False])
@pytest.mark.parametrize("min_count", [0, 4])
def test_integer_array_sum(skipna, min_count, any_nullable_int_dtype):
dtype = any_nullable_int_dtype
def test_integer_array_sum(skipna, min_count, any_int_ea_dtype):
dtype = any_int_ea_dtype
arr = pd.array([1, 2, 3, None], dtype=dtype)
result = arr.sum(skipna=skipna, min_count=min_count)
if skipna and min_count == 0:
Expand All @@ -148,8 +148,8 @@ def test_integer_array_sum(skipna, min_count, any_nullable_int_dtype):

@pytest.mark.parametrize("skipna", [True, False])
@pytest.mark.parametrize("method", ["min", "max"])
def test_integer_array_min_max(skipna, method, any_nullable_int_dtype):
dtype = any_nullable_int_dtype
def test_integer_array_min_max(skipna, method, any_int_ea_dtype):
dtype = any_int_ea_dtype
arr = pd.array([0, 1, None], dtype=dtype)
func = getattr(arr, method)
result = func(skipna=skipna)
Expand All @@ -161,8 +161,8 @@ def test_integer_array_min_max(skipna, method, any_nullable_int_dtype):

@pytest.mark.parametrize("skipna", [True, False])
@pytest.mark.parametrize("min_count", [0, 9])
def test_integer_array_prod(skipna, min_count, any_nullable_int_dtype):
dtype = any_nullable_int_dtype
def test_integer_array_prod(skipna, min_count, any_int_ea_dtype):
dtype = any_int_ea_dtype
arr = pd.array([1, 2, None], dtype=dtype)
result = arr.prod(skipna=skipna, min_count=min_count)
if skipna and min_count == 0:
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/arrays/masked/test_arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from pandas.core.arrays import ExtensionArray

# integer dtypes
arrays = [pd.array([1, 2, 3, None], dtype=dtype) for dtype in tm.ALL_EA_INT_DTYPES]
arrays = [pd.array([1, 2, 3, None], dtype=dtype) for dtype in tm.ALL_INT_EA_DTYPES]
scalars: list[Any] = [2] * len(arrays)
# floating dtypes
arrays += [pd.array([0.1, 0.2, 0.3, None], dtype=dtype) for dtype in tm.FLOAT_EA_DTYPES]
Expand Down
6 changes: 3 additions & 3 deletions pandas/tests/arrays/masked/test_arrow_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from pandas.core.arrays._arrow_utils import pyarrow_array_to_numpy_and_mask

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

Expand Down Expand Up @@ -85,8 +85,8 @@ def test_arrow_sliced(data):


@pytest.fixture
def np_dtype_to_arrays(any_real_dtype):
np_dtype = np.dtype(any_real_dtype)
def np_dtype_to_arrays(any_real_numpy_dtype):
np_dtype = np.dtype(any_real_numpy_dtype)
pa_type = pa.from_numpy_dtype(np_dtype)

# None ensures the creation of a bitmask buffer.
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/arrays/masked/test_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pandas as pd
import pandas._testing as tm

arrays = [pd.array([1, 2, 3, None], dtype=dtype) for dtype in tm.ALL_EA_INT_DTYPES]
arrays = [pd.array([1, 2, 3, None], dtype=dtype) for dtype in tm.ALL_INT_EA_DTYPES]
arrays += [
pd.array([0.141, -0.268, 5.895, None], dtype=dtype) for dtype in tm.FLOAT_EA_DTYPES
]
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/arrays/sparse/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,10 +511,10 @@ def test_astype_bool(self):
)
tm.assert_sp_array_equal(result, expected)

def test_astype_all(self, any_real_dtype):
def test_astype_all(self, any_real_numpy_dtype):
vals = np.array([1, 2, 3])
arr = SparseArray(vals, fill_value=1)
typ = np.dtype(any_real_dtype)
typ = np.dtype(any_real_numpy_dtype)
res = arr.astype(typ)
assert res.dtype == SparseDtype(typ, 1)
assert res.sp_values.dtype == typ
Expand Down
6 changes: 3 additions & 3 deletions pandas/tests/arrays/string_/test_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,11 @@ def test_astype_nullable_int(dtype):
tm.assert_extension_array_equal(result, expected)


def test_astype_float(dtype, any_float_allowed_nullable_dtype):
def test_astype_float(dtype, any_float_dtype):
# Don't compare arrays (37974)
ser = pd.Series(["1.1", pd.NA, "3.3"], dtype=dtype)
result = ser.astype(any_float_allowed_nullable_dtype)
expected = pd.Series([1.1, np.nan, 3.3], dtype=any_float_allowed_nullable_dtype)
result = ser.astype(any_float_dtype)
expected = pd.Series([1.1, np.nan, 3.3], dtype=any_float_dtype)
tm.assert_series_equal(result, expected)


Expand Down
Loading

0 comments on commit c0663f8

Please sign in to comment.