From c0663f8972b5a3ae19156e7ec0c9f57062a0fc11 Mon Sep 17 00:00:00 2001 From: pratyushsharan Date: Wed, 18 Aug 2021 22:52:24 +0530 Subject: [PATCH] TST: cleanup of any_* test fixtures GH38017 (#43047) --- asv_bench/benchmarks/dtypes.py | 6 +-- pandas/_testing/__init__.py | 20 ++++----- pandas/conftest.py | 40 ++++++++--------- pandas/tests/arithmetic/test_numeric.py | 13 ++++-- pandas/tests/arithmetic/test_timedelta64.py | 17 ++++--- .../tests/arrays/integer/test_arithmetic.py | 6 +-- .../tests/arrays/integer/test_comparison.py | 8 ++-- pandas/tests/arrays/integer/test_function.py | 12 ++--- pandas/tests/arrays/masked/test_arithmetic.py | 2 +- .../tests/arrays/masked/test_arrow_compat.py | 6 +-- pandas/tests/arrays/masked/test_function.py | 2 +- pandas/tests/arrays/sparse/test_array.py | 4 +- pandas/tests/arrays/string_/test_string.py | 6 +-- pandas/tests/arrays/test_array.py | 12 ++--- pandas/tests/dtypes/cast/test_downcast.py | 12 ++--- pandas/tests/dtypes/cast/test_infer_dtype.py | 12 ++--- pandas/tests/dtypes/cast/test_promote.py | 12 ++--- pandas/tests/dtypes/test_common.py | 44 +++++++++---------- pandas/tests/frame/indexing/test_where.py | 4 +- pandas/tests/frame/methods/test_astype.py | 8 ++-- pandas/tests/frame/methods/test_diff.py | 8 ++-- pandas/tests/frame/test_constructors.py | 10 ++--- .../tests/groupby/test_groupby_shift_diff.py | 9 ++-- pandas/tests/groupby/test_libgroupby.py | 4 +- .../indexes/datetimes/test_constructors.py | 4 +- pandas/tests/indexes/numeric/test_numeric.py | 15 ++++--- pandas/tests/indexing/test_categorical.py | 6 +-- pandas/tests/indexing/test_loc.py | 6 +-- pandas/tests/io/formats/test_to_string.py | 4 +- pandas/tests/io/json/test_ujson.py | 36 +++++++-------- pandas/tests/reshape/merge/test_merge_asof.py | 16 +++---- pandas/tests/reshape/test_qcut.py | 4 +- pandas/tests/series/indexing/test_getitem.py | 4 +- pandas/tests/series/indexing/test_setitem.py | 16 +++---- pandas/tests/series/indexing/test_where.py | 15 ++++--- pandas/tests/series/methods/test_clip.py | 14 ++---- pandas/tests/series/methods/test_nlargest.py | 18 ++++---- pandas/tests/series/methods/test_replace.py | 8 ++-- pandas/tests/series/methods/test_round.py | 20 ++++----- pandas/tests/series/test_constructors.py | 18 ++++---- pandas/tests/series/test_unary.py | 4 +- pandas/tests/test_algos.py | 4 +- pandas/tests/util/test_assert_frame_equal.py | 8 ++-- pandas/tests/window/test_ewm.py | 4 +- pandas/tests/window/test_rolling.py | 9 ++-- 45 files changed, 262 insertions(+), 248 deletions(-) diff --git a/asv_bench/benchmarks/dtypes.py b/asv_bench/benchmarks/dtypes.py index c561b80ed1ca6d..c45d5a0814544a 100644 --- a/asv_bench/benchmarks/dtypes.py +++ b/asv_bench/benchmarks/dtypes.py @@ -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 diff --git a/pandas/_testing/__init__.py b/pandas/_testing/__init__.py index f11d9c10ea85f4..fd74409e39a828 100644 --- a/pandas/_testing/__init__.py +++ b/pandas/_testing/__init__.py @@ -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"] @@ -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 diff --git a/pandas/conftest.py b/pandas/conftest.py index 460f34fd021099..46975aa039b18f 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -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. @@ -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. @@ -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. @@ -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. @@ -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. @@ -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. @@ -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. @@ -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. @@ -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. @@ -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. diff --git a/pandas/tests/arithmetic/test_numeric.py b/pandas/tests/arithmetic/test_numeric.py index 844bdd4bd1944e..7ee8ae7a7ec8c2 100644 --- a/pandas/tests/arithmetic/test_numeric.py +++ b/pandas/tests/arithmetic/test_numeric.py @@ -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) @@ -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) diff --git a/pandas/tests/arithmetic/test_timedelta64.py b/pandas/tests/arithmetic/test_timedelta64.py index daebdb542bc201..1984c6c9bbe439 100644 --- a/pandas/tests/arithmetic/test_timedelta64.py +++ b/pandas/tests/arithmetic/test_timedelta64.py @@ -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): @@ -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]") @@ -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]") diff --git a/pandas/tests/arrays/integer/test_arithmetic.py b/pandas/tests/arrays/integer/test_arithmetic.py index 2eb88b669bcb16..4f66e2ecfd3553 100644 --- a/pandas/tests/arrays/integer/test_arithmetic.py +++ b/pandas/tests/arrays/integer/test_arithmetic.py @@ -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) diff --git a/pandas/tests/arrays/integer/test_comparison.py b/pandas/tests/arrays/integer/test_comparison.py index 1767250af09b05..2f12ffacfb4192 100644 --- a/pandas/tests/arrays/integer/test_comparison.py +++ b/pandas/tests/arrays/integer/test_comparison.py @@ -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) diff --git a/pandas/tests/arrays/integer/test_function.py b/pandas/tests/arrays/integer/test_function.py index 6d10058be71e03..6f53b447769007 100644 --- a/pandas/tests/arrays/integer/test_function.py +++ b/pandas/tests/arrays/integer/test_function.py @@ -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: @@ -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) @@ -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: diff --git a/pandas/tests/arrays/masked/test_arithmetic.py b/pandas/tests/arrays/masked/test_arithmetic.py index bea94095452bdf..57086bf92b8903 100644 --- a/pandas/tests/arrays/masked/test_arithmetic.py +++ b/pandas/tests/arrays/masked/test_arithmetic.py @@ -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] diff --git a/pandas/tests/arrays/masked/test_arrow_compat.py b/pandas/tests/arrays/masked/test_arrow_compat.py index 9f755412dbf39f..d66a603ad568c8 100644 --- a/pandas/tests/arrays/masked/test_arrow_compat.py +++ b/pandas/tests/arrays/masked/test_arrow_compat.py @@ -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")] @@ -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. diff --git a/pandas/tests/arrays/masked/test_function.py b/pandas/tests/arrays/masked/test_function.py index 1c0e0820f7dccf..bf310c7aa455ec 100644 --- a/pandas/tests/arrays/masked/test_function.py +++ b/pandas/tests/arrays/masked/test_function.py @@ -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 ] diff --git a/pandas/tests/arrays/sparse/test_array.py b/pandas/tests/arrays/sparse/test_array.py index 1cc8a2df448120..db96b4aa535ad2 100644 --- a/pandas/tests/arrays/sparse/test_array.py +++ b/pandas/tests/arrays/sparse/test_array.py @@ -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 diff --git a/pandas/tests/arrays/string_/test_string.py b/pandas/tests/arrays/string_/test_string.py index c6240600d3a050..fa564ac76f8bbe 100644 --- a/pandas/tests/arrays/string_/test_string.py +++ b/pandas/tests/arrays/string_/test_string.py @@ -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) diff --git a/pandas/tests/arrays/test_array.py b/pandas/tests/arrays/test_array.py index 958ccec930f0e7..cc8a47f545d928 100644 --- a/pandas/tests/arrays/test_array.py +++ b/pandas/tests/arrays/test_array.py @@ -392,8 +392,8 @@ def test_searchsorted(self, string_dtype): assert is_scalar(result) assert result == 1 - def test_searchsorted_numeric_dtypes_scalar(self, any_real_dtype): - arr = pd.array([1, 3, 90], dtype=any_real_dtype) + def test_searchsorted_numeric_dtypes_scalar(self, any_real_numpy_dtype): + arr = pd.array([1, 3, 90], dtype=any_real_numpy_dtype) result = arr.searchsorted(30) assert is_scalar(result) assert result == 2 @@ -402,8 +402,8 @@ def test_searchsorted_numeric_dtypes_scalar(self, any_real_dtype): expected = np.array([2], dtype=np.intp) tm.assert_numpy_array_equal(result, expected) - def test_searchsorted_numeric_dtypes_vector(self, any_real_dtype): - arr = pd.array([1, 3, 90], dtype=any_real_dtype) + def test_searchsorted_numeric_dtypes_vector(self, any_real_numpy_dtype): + arr = pd.array([1, 3, 90], dtype=any_real_numpy_dtype) result = arr.searchsorted([2, 30]) expected = np.array([1, 2], dtype=np.intp) tm.assert_numpy_array_equal(result, expected) @@ -431,8 +431,8 @@ def test_search_sorted_datetime64_scalar(self, arr, val): assert is_scalar(result) assert result == 1 - def test_searchsorted_sorter(self, any_real_dtype): - arr = pd.array([3, 1, 2], dtype=any_real_dtype) + def test_searchsorted_sorter(self, any_real_numpy_dtype): + arr = pd.array([3, 1, 2], dtype=any_real_numpy_dtype) result = arr.searchsorted([0, 3], sorter=np.argsort(arr)) expected = np.array([0, 2], dtype=np.intp) tm.assert_numpy_array_equal(result, expected) diff --git a/pandas/tests/dtypes/cast/test_downcast.py b/pandas/tests/dtypes/cast/test_downcast.py index 5217b38f155c86..b1efc1e5677fdc 100644 --- a/pandas/tests/dtypes/cast/test_downcast.py +++ b/pandas/tests/dtypes/cast/test_downcast.py @@ -50,8 +50,8 @@ def test_downcast_booleans(): tm.assert_series_equal(result, expected) -def test_downcast_conversion_no_nan(any_real_dtype): - dtype = any_real_dtype +def test_downcast_conversion_no_nan(any_real_numpy_dtype): + dtype = any_real_numpy_dtype expected = np.array([1, 2]) arr = np.array([1.0, 2.0], dtype=dtype) @@ -59,8 +59,8 @@ def test_downcast_conversion_no_nan(any_real_dtype): tm.assert_almost_equal(result, expected, check_dtype=False) -def test_downcast_conversion_nan(float_dtype): - dtype = float_dtype +def test_downcast_conversion_nan(float_numpy_dtype): + dtype = float_numpy_dtype data = [1.0, 2.0, np.nan] expected = np.array(data, dtype=dtype) @@ -70,8 +70,8 @@ def test_downcast_conversion_nan(float_dtype): tm.assert_almost_equal(result, expected) -def test_downcast_conversion_empty(any_real_dtype): - dtype = any_real_dtype +def test_downcast_conversion_empty(any_real_numpy_dtype): + dtype = any_real_numpy_dtype arr = np.array([], dtype=dtype) result = maybe_downcast_to_dtype(arr, np.dtype("int64")) tm.assert_numpy_array_equal(result, np.array([], dtype=np.int64)) diff --git a/pandas/tests/dtypes/cast/test_infer_dtype.py b/pandas/tests/dtypes/cast/test_infer_dtype.py index b08dc82a48fe35..902130bf93d541 100644 --- a/pandas/tests/dtypes/cast/test_infer_dtype.py +++ b/pandas/tests/dtypes/cast/test_infer_dtype.py @@ -30,20 +30,20 @@ def pandas_dtype(request): return request.param -def test_infer_dtype_from_int_scalar(any_int_dtype): +def test_infer_dtype_from_int_scalar(any_int_numpy_dtype): # Test that infer_dtype_from_scalar is # returning correct dtype for int and float. - data = np.dtype(any_int_dtype).type(12) + data = np.dtype(any_int_numpy_dtype).type(12) dtype, val = infer_dtype_from_scalar(data) assert dtype == type(data) -def test_infer_dtype_from_float_scalar(float_dtype): - float_dtype = np.dtype(float_dtype).type - data = float_dtype(12) +def test_infer_dtype_from_float_scalar(float_numpy_dtype): + float_numpy_dtype = np.dtype(float_numpy_dtype).type + data = float_numpy_dtype(12) dtype, val = infer_dtype_from_scalar(data) - assert dtype == float_dtype + assert dtype == float_numpy_dtype @pytest.mark.parametrize( diff --git a/pandas/tests/dtypes/cast/test_promote.py b/pandas/tests/dtypes/cast/test_promote.py index f4ad3c6285f74b..e8a3b5d28ee636 100644 --- a/pandas/tests/dtypes/cast/test_promote.py +++ b/pandas/tests/dtypes/cast/test_promote.py @@ -240,9 +240,9 @@ def test_maybe_promote_int_with_int(dtype, fill_value, expected_dtype): _check_promote(dtype, fill_value, expected_dtype, exp_val_for_scalar) -def test_maybe_promote_int_with_float(any_int_dtype, float_dtype): - dtype = np.dtype(any_int_dtype) - fill_dtype = np.dtype(float_dtype) +def test_maybe_promote_int_with_float(any_int_numpy_dtype, float_numpy_dtype): + dtype = np.dtype(any_int_numpy_dtype) + fill_dtype = np.dtype(float_numpy_dtype) # create array of given dtype; casts "1" to correct dtype fill_value = np.array([1], dtype=fill_dtype)[0] @@ -255,10 +255,10 @@ def test_maybe_promote_int_with_float(any_int_dtype, float_dtype): _check_promote(dtype, fill_value, expected_dtype, exp_val_for_scalar) -def test_maybe_promote_float_with_int(float_dtype, any_int_dtype): +def test_maybe_promote_float_with_int(float_numpy_dtype, any_int_numpy_dtype): - dtype = np.dtype(float_dtype) - fill_dtype = np.dtype(any_int_dtype) + dtype = np.dtype(float_numpy_dtype) + fill_dtype = np.dtype(any_int_numpy_dtype) # create array of given dtype; casts "1" to correct dtype fill_value = np.array([1], dtype=fill_dtype)[0] diff --git a/pandas/tests/dtypes/test_common.py b/pandas/tests/dtypes/test_common.py index a2244c4aab9232..14f6557fbc31ee 100644 --- a/pandas/tests/dtypes/test_common.py +++ b/pandas/tests/dtypes/test_common.py @@ -295,10 +295,10 @@ def test_is_string_dtype_nullable(nullable_string_dtype): "dtype", integer_dtypes + [pd.Series([1, 2])] - + tm.ALL_INT_DTYPES - + to_numpy_dtypes(tm.ALL_INT_DTYPES) - + tm.ALL_EA_INT_DTYPES - + to_ea_dtypes(tm.ALL_EA_INT_DTYPES), + + tm.ALL_INT_NUMPY_DTYPES + + to_numpy_dtypes(tm.ALL_INT_NUMPY_DTYPES) + + tm.ALL_INT_EA_DTYPES + + to_ea_dtypes(tm.ALL_INT_EA_DTYPES), ) def test_is_integer_dtype(dtype): assert com.is_integer_dtype(dtype) @@ -327,10 +327,10 @@ def test_is_not_integer_dtype(dtype): "dtype", signed_integer_dtypes + [pd.Series([1, 2])] - + tm.SIGNED_INT_DTYPES - + to_numpy_dtypes(tm.SIGNED_INT_DTYPES) - + tm.SIGNED_EA_INT_DTYPES - + to_ea_dtypes(tm.SIGNED_EA_INT_DTYPES), + + tm.SIGNED_INT_NUMPY_DTYPES + + to_numpy_dtypes(tm.SIGNED_INT_NUMPY_DTYPES) + + tm.SIGNED_INT_EA_DTYPES + + to_ea_dtypes(tm.SIGNED_INT_EA_DTYPES), ) def test_is_signed_integer_dtype(dtype): assert com.is_integer_dtype(dtype) @@ -347,10 +347,10 @@ def test_is_signed_integer_dtype(dtype): np.array(["a", "b"]), np.array([], dtype=np.timedelta64), ] - + tm.UNSIGNED_INT_DTYPES - + to_numpy_dtypes(tm.UNSIGNED_INT_DTYPES) - + tm.UNSIGNED_EA_INT_DTYPES - + to_ea_dtypes(tm.UNSIGNED_EA_INT_DTYPES), + + tm.UNSIGNED_INT_NUMPY_DTYPES + + to_numpy_dtypes(tm.UNSIGNED_INT_NUMPY_DTYPES) + + tm.UNSIGNED_INT_EA_DTYPES + + to_ea_dtypes(tm.UNSIGNED_INT_EA_DTYPES), ) def test_is_not_signed_integer_dtype(dtype): assert not com.is_signed_integer_dtype(dtype) @@ -363,10 +363,10 @@ def test_is_not_signed_integer_dtype(dtype): "dtype", unsigned_integer_dtypes + [pd.Series([1, 2], dtype=np.uint32)] - + tm.UNSIGNED_INT_DTYPES - + to_numpy_dtypes(tm.UNSIGNED_INT_DTYPES) - + tm.UNSIGNED_EA_INT_DTYPES - + to_ea_dtypes(tm.UNSIGNED_EA_INT_DTYPES), + + tm.UNSIGNED_INT_NUMPY_DTYPES + + to_numpy_dtypes(tm.UNSIGNED_INT_NUMPY_DTYPES) + + tm.UNSIGNED_INT_EA_DTYPES + + to_ea_dtypes(tm.UNSIGNED_INT_EA_DTYPES), ) def test_is_unsigned_integer_dtype(dtype): assert com.is_unsigned_integer_dtype(dtype) @@ -383,10 +383,10 @@ def test_is_unsigned_integer_dtype(dtype): np.array(["a", "b"]), np.array([], dtype=np.timedelta64), ] - + tm.SIGNED_INT_DTYPES - + to_numpy_dtypes(tm.SIGNED_INT_DTYPES) - + tm.SIGNED_EA_INT_DTYPES - + to_ea_dtypes(tm.SIGNED_EA_INT_DTYPES), + + tm.SIGNED_INT_NUMPY_DTYPES + + to_numpy_dtypes(tm.SIGNED_INT_NUMPY_DTYPES) + + tm.SIGNED_INT_EA_DTYPES + + to_ea_dtypes(tm.SIGNED_INT_EA_DTYPES), ) def test_is_not_unsigned_integer_dtype(dtype): assert not com.is_unsigned_integer_dtype(dtype) @@ -722,9 +722,9 @@ def test_astype_nansafe(val, typ): astype_nansafe(arr, dtype=typ) -def test_astype_nansafe_copy_false(any_int_dtype): +def test_astype_nansafe_copy_false(any_int_numpy_dtype): # GH#34457 use astype, not view - arr = np.array([1, 2, 3], dtype=any_int_dtype) + arr = np.array([1, 2, 3], dtype=any_int_numpy_dtype) dtype = np.dtype("float64") result = astype_nansafe(arr, dtype, copy=False) diff --git a/pandas/tests/frame/indexing/test_where.py b/pandas/tests/frame/indexing/test_where.py index 0405d150c0c04d..e23a893e0538d1 100644 --- a/pandas/tests/frame/indexing/test_where.py +++ b/pandas/tests/frame/indexing/test_where.py @@ -316,11 +316,11 @@ def test_where_bug(self): assert return_value is None tm.assert_frame_equal(result, expected) - def test_where_bug_mixed(self, sint_dtype): + def test_where_bug_mixed(self, any_signed_int_numpy_dtype): # see gh-2793 df = DataFrame( { - "a": np.array([1, 2, 3, 4], dtype=sint_dtype), + "a": np.array([1, 2, 3, 4], dtype=any_signed_int_numpy_dtype), "b": np.array([4.0, 3.0, 2.0, 1.0], dtype="float64"), } ) diff --git a/pandas/tests/frame/methods/test_astype.py b/pandas/tests/frame/methods/test_astype.py index 775a5a38768e62..398c66584390bd 100644 --- a/pandas/tests/frame/methods/test_astype.py +++ b/pandas/tests/frame/methods/test_astype.py @@ -709,15 +709,13 @@ def test_astype_from_categorical4(self): df["cats"] = df["cats"].astype("category") tm.assert_frame_equal(exp_df, df) - def test_categorical_astype_to_int(self, any_int_or_nullable_int_dtype): + def test_categorical_astype_to_int(self, any_int_dtype): # GH#39402 df = DataFrame(data={"col1": pd.array([2.0, 1.0, 3.0])}) df.col1 = df.col1.astype("category") - df.col1 = df.col1.astype(any_int_or_nullable_int_dtype) - expected = DataFrame( - {"col1": pd.array([2, 1, 3], dtype=any_int_or_nullable_int_dtype)} - ) + df.col1 = df.col1.astype(any_int_dtype) + expected = DataFrame({"col1": pd.array([2, 1, 3], dtype=any_int_dtype)}) tm.assert_frame_equal(df, expected) def test_astype_categorical_to_string_missing(self): diff --git a/pandas/tests/frame/methods/test_diff.py b/pandas/tests/frame/methods/test_diff.py index 0a3d2e1c9a8fc9..5fd6928f11f44b 100644 --- a/pandas/tests/frame/methods/test_diff.py +++ b/pandas/tests/frame/methods/test_diff.py @@ -286,11 +286,13 @@ def test_diff_readonly(self): expected = DataFrame(np.array(df)).diff() tm.assert_frame_equal(result, expected) - def test_diff_all_int_dtype(self, any_int_dtype): + def test_diff_all_int_dtype(self, any_int_numpy_dtype): # GH 14773 df = DataFrame(range(5)) - df = df.astype(any_int_dtype) + df = df.astype(any_int_numpy_dtype) result = df.diff() - expected_dtype = "float32" if any_int_dtype in ("int8", "int16") else "float64" + expected_dtype = ( + "float32" if any_int_numpy_dtype in ("int8", "int16") else "float64" + ) expected = DataFrame([np.nan, 1.0, 1.0, 1.0, 1.0], dtype=expected_dtype) tm.assert_frame_equal(result, expected) diff --git a/pandas/tests/frame/test_constructors.py b/pandas/tests/frame/test_constructors.py index 6bf12a843eb9ae..07124ccc20336d 100644 --- a/pandas/tests/frame/test_constructors.py +++ b/pandas/tests/frame/test_constructors.py @@ -2257,9 +2257,9 @@ def test_constructor_categorical_series(self): @pytest.mark.parametrize( "dtype", - 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 @@ -2428,14 +2428,14 @@ def test_constructor_list_str_na(self, string_dtype): @pytest.mark.parametrize("copy", [False, True]) @td.skip_array_manager_not_yet_implemented - def test_dict_nocopy(self, copy, any_nullable_numeric_dtype, any_numpy_dtype): + def test_dict_nocopy(self, copy, any_numeric_ea_dtype, any_numpy_dtype): a = np.array([1, 2], dtype=any_numpy_dtype) b = np.array([3, 4], dtype=any_numpy_dtype) if b.dtype.kind in ["S", "U"]: # These get cast, making the checks below more cumbersome return - c = pd.array([1, 2], dtype=any_nullable_numeric_dtype) + c = pd.array([1, 2], dtype=any_numeric_ea_dtype) df = DataFrame({"a": a, "b": b, "c": c}, copy=copy) def get_base(obj): diff --git a/pandas/tests/groupby/test_groupby_shift_diff.py b/pandas/tests/groupby/test_groupby_shift_diff.py index e9517b4544f0b8..3ddb52674c5e9a 100644 --- a/pandas/tests/groupby/test_groupby_shift_diff.py +++ b/pandas/tests/groupby/test_groupby_shift_diff.py @@ -69,11 +69,14 @@ def test_group_shift_lose_timezone(): tm.assert_series_equal(result, expected) -def test_group_diff_real(any_real_dtype): - df = DataFrame({"a": [1, 2, 3, 3, 2], "b": [1, 2, 3, 4, 5]}, dtype=any_real_dtype) +def test_group_diff_real(any_real_numpy_dtype): + df = DataFrame( + {"a": [1, 2, 3, 3, 2], "b": [1, 2, 3, 4, 5]}, + dtype=any_real_numpy_dtype, + ) result = df.groupby("a")["b"].diff() exp_dtype = "float" - if any_real_dtype in ["int8", "int16", "float32"]: + if any_real_numpy_dtype in ["int8", "int16", "float32"]: exp_dtype = "float32" expected = Series([np.nan, np.nan, np.nan, 1.0, 3.0], dtype=exp_dtype, name="b") tm.assert_series_equal(result, expected) diff --git a/pandas/tests/groupby/test_libgroupby.py b/pandas/tests/groupby/test_libgroupby.py index 7a9cadb6c8232d..3eb25878876b20 100644 --- a/pandas/tests/groupby/test_libgroupby.py +++ b/pandas/tests/groupby/test_libgroupby.py @@ -184,9 +184,9 @@ def _check_cython_group_transform_cumulative(pd_op, np_op, dtype): tm.assert_numpy_array_equal(np_op(data), answer[:, 0], check_dtype=False) -def test_cython_group_transform_cumsum(any_real_dtype): +def test_cython_group_transform_cumsum(any_real_numpy_dtype): # see gh-4095 - dtype = np.dtype(any_real_dtype).type + dtype = np.dtype(any_real_numpy_dtype).type pd_op, np_op = group_cumsum, np.cumsum _check_cython_group_transform_cumulative(pd_op, np_op, dtype) diff --git a/pandas/tests/indexes/datetimes/test_constructors.py b/pandas/tests/indexes/datetimes/test_constructors.py index 4e78b8cd7fb6ce..86dc6bd0e76ea0 100644 --- a/pandas/tests/indexes/datetimes/test_constructors.py +++ b/pandas/tests/indexes/datetimes/test_constructors.py @@ -942,7 +942,7 @@ def test_dti_constructor_years_only(self, tz_naive_fixture): ]: tm.assert_index_equal(rng, expected) - def test_dti_constructor_small_int(self, any_int_dtype): + def test_dti_constructor_small_int(self, any_int_numpy_dtype): # see gh-13721 exp = DatetimeIndex( [ @@ -952,7 +952,7 @@ def test_dti_constructor_small_int(self, any_int_dtype): ] ) - arr = np.array([0, 10, 20], dtype=any_int_dtype) + arr = np.array([0, 10, 20], dtype=any_int_numpy_dtype) tm.assert_index_equal(DatetimeIndex(arr), exp) def test_ctor_str_intraday(self): diff --git a/pandas/tests/indexes/numeric/test_numeric.py b/pandas/tests/indexes/numeric/test_numeric.py index 960412df9e6e27..6d35568b69face 100644 --- a/pandas/tests/indexes/numeric/test_numeric.py +++ b/pandas/tests/indexes/numeric/test_numeric.py @@ -151,16 +151,16 @@ def test_constructor_explicit(self, mixed_index, float_index): mixed_index, Index([1.5, 2, 3, 4, 5], dtype=object), is_float_index=False ) - def test_type_coercion_fail(self, any_int_dtype): + def test_type_coercion_fail(self, any_int_numpy_dtype): # see gh-15832 msg = "Trying to coerce float values to integers" with pytest.raises(ValueError, match=msg): - Index([1, 2, 3.5], dtype=any_int_dtype) + Index([1, 2, 3.5], dtype=any_int_numpy_dtype) - def test_type_coercion_valid(self, float_dtype): + def test_type_coercion_valid(self, float_numpy_dtype): # There is no Float32Index, so we always # generate Float64Index. - idx = Index([1, 2, 3.5], dtype=float_dtype) + idx = Index([1, 2, 3.5], dtype=float_numpy_dtype) tm.assert_index_equal(idx, Index([1, 2, 3.5]), exact=True) def test_equals_numeric(self): @@ -496,13 +496,16 @@ def test_constructor_corner(self, dtype): with pytest.raises(TypeError, match="casting"): index_cls(arr, dtype=dtype) - def test_constructor_coercion_signed_to_unsigned(self, uint_dtype): + def test_constructor_coercion_signed_to_unsigned( + self, + any_unsigned_int_numpy_dtype, + ): # see gh-15832 msg = "Trying to coerce negative values to unsigned integers" with pytest.raises(OverflowError, match=msg): - Index([-1], dtype=uint_dtype) + Index([-1], dtype=any_unsigned_int_numpy_dtype) def test_coerce_list(self): # coerce things diff --git a/pandas/tests/indexing/test_categorical.py b/pandas/tests/indexing/test_categorical.py index 9908f792080881..870043897e8e29 100644 --- a/pandas/tests/indexing/test_categorical.py +++ b/pandas/tests/indexing/test_categorical.py @@ -485,9 +485,9 @@ def test_loc_and_at_with_categorical_index(self): [1.5, 2.5, 3.5], [-1.5, -2.5, -3.5], # numpy int/uint - *(np.array([1, 2, 3], dtype=dtype) for dtype in tm.ALL_INT_DTYPES), + *(np.array([1, 2, 3], dtype=dtype) for dtype in tm.ALL_INT_NUMPY_DTYPES), # numpy floats - *(np.array([1.5, 2.5, 3.5], dtype=dtyp) for dtyp in tm.FLOAT_DTYPES), + *(np.array([1.5, 2.5, 3.5], dtype=dtyp) for dtyp in tm.FLOAT_NUMPY_DTYPES), # numpy object np.array([1, "b", 3.5], dtype=object), # pandas scalars @@ -495,7 +495,7 @@ def test_loc_and_at_with_categorical_index(self): [Timestamp(2019, 1, 1), Timestamp(2019, 2, 1), Timestamp(2019, 3, 1)], [Timedelta(1, "d"), Timedelta(2, "d"), Timedelta(3, "D")], # pandas Integer arrays - *(pd.array([1, 2, 3], dtype=dtype) for dtype in tm.ALL_EA_INT_DTYPES), + *(pd.array([1, 2, 3], dtype=dtype) for dtype in tm.ALL_INT_EA_DTYPES), # other pandas arrays pd.IntervalIndex.from_breaks([1, 4, 6, 9]).array, pd.date_range("2019-01-01", periods=3).array, diff --git a/pandas/tests/indexing/test_loc.py b/pandas/tests/indexing/test_loc.py index 165c7b8414e4a7..bf23f3844544d1 100644 --- a/pandas/tests/indexing/test_loc.py +++ b/pandas/tests/indexing/test_loc.py @@ -1409,12 +1409,12 @@ def test_loc_setitem_unsorted_multiindex_columns(self, key): expected = expected.sort_index(axis=1) tm.assert_frame_equal(df, expected) - def test_loc_setitem_uint_drop(self, any_int_dtype): + def test_loc_setitem_uint_drop(self, any_int_numpy_dtype): # see GH#18311 # assigning series.loc[0] = 4 changed series.dtype to int - series = Series([1, 2, 3], dtype=any_int_dtype) + series = Series([1, 2, 3], dtype=any_int_numpy_dtype) series.loc[0] = 4 - expected = Series([4, 2, 3], dtype=any_int_dtype) + expected = Series([4, 2, 3], dtype=any_int_numpy_dtype) tm.assert_series_equal(series, expected) def test_loc_setitem_td64_non_nano(self): diff --git a/pandas/tests/io/formats/test_to_string.py b/pandas/tests/io/formats/test_to_string.py index 65a438ad6108b9..1d3804a9554331 100644 --- a/pandas/tests/io/formats/test_to_string.py +++ b/pandas/tests/io/formats/test_to_string.py @@ -289,9 +289,9 @@ def test_nullable_float_to_string(float_ea_dtype): assert result == expected -def test_nullable_int_to_string(any_nullable_int_dtype): +def test_nullable_int_to_string(any_int_ea_dtype): # https://github.com/pandas-dev/pandas/issues/36775 - dtype = any_nullable_int_dtype + dtype = any_int_ea_dtype s = Series([0, 1, None], dtype=dtype) result = s.to_string() expected = dedent( diff --git a/pandas/tests/io/json/test_ujson.py b/pandas/tests/io/json/test_ujson.py index 58ccd31b7c940e..b5c22e959b4d7a 100644 --- a/pandas/tests/io/json/test_ujson.py +++ b/pandas/tests/io/json/test_ujson.py @@ -749,55 +749,55 @@ def test_bool_array(self): output = np.array(ujson.decode(ujson.encode(bool_array)), dtype=bool) tm.assert_numpy_array_equal(bool_array, output) - def test_int(self, any_int_dtype): - klass = np.dtype(any_int_dtype).type + def test_int(self, any_int_numpy_dtype): + klass = np.dtype(any_int_numpy_dtype).type num = klass(1) assert klass(ujson.decode(ujson.encode(num))) == num - def test_int_array(self, any_int_dtype): + def test_int_array(self, any_int_numpy_dtype): arr = np.arange(100, dtype=int) - arr_input = arr.astype(any_int_dtype) + arr_input = arr.astype(any_int_numpy_dtype) arr_output = np.array( - ujson.decode(ujson.encode(arr_input)), dtype=any_int_dtype + ujson.decode(ujson.encode(arr_input)), dtype=any_int_numpy_dtype ) tm.assert_numpy_array_equal(arr_input, arr_output) - def test_int_max(self, any_int_dtype): - if any_int_dtype in ("int64", "uint64") and not IS64: + def test_int_max(self, any_int_numpy_dtype): + if any_int_numpy_dtype in ("int64", "uint64") and not IS64: pytest.skip("Cannot test 64-bit integer on 32-bit platform") - klass = np.dtype(any_int_dtype).type + klass = np.dtype(any_int_numpy_dtype).type # uint64 max will always overflow, # as it's encoded to signed. - if any_int_dtype == "uint64": + if any_int_numpy_dtype == "uint64": num = np.iinfo("int64").max else: - num = np.iinfo(any_int_dtype).max + num = np.iinfo(any_int_numpy_dtype).max assert klass(ujson.decode(ujson.encode(num))) == num - def test_float(self, float_dtype): - klass = np.dtype(float_dtype).type + def test_float(self, float_numpy_dtype): + klass = np.dtype(float_numpy_dtype).type num = klass(256.2013) assert klass(ujson.decode(ujson.encode(num))) == num - def test_float_array(self, float_dtype): + def test_float_array(self, float_numpy_dtype): arr = np.arange(12.5, 185.72, 1.7322, dtype=float) - float_input = arr.astype(float_dtype) + float_input = arr.astype(float_numpy_dtype) float_output = np.array( ujson.decode(ujson.encode(float_input, double_precision=15)), - dtype=float_dtype, + dtype=float_numpy_dtype, ) tm.assert_almost_equal(float_input, float_output) - def test_float_max(self, float_dtype): - klass = np.dtype(float_dtype).type - num = klass(np.finfo(float_dtype).max / 10) + def test_float_max(self, float_numpy_dtype): + klass = np.dtype(float_numpy_dtype).type + num = klass(np.finfo(float_numpy_dtype).max / 10) tm.assert_almost_equal( klass(ujson.decode(ujson.encode(num, double_precision=15))), num diff --git a/pandas/tests/reshape/merge/test_merge_asof.py b/pandas/tests/reshape/merge/test_merge_asof.py index 310cf2debadc6f..5bb9f56adb8d54 100644 --- a/pandas/tests/reshape/merge/test_merge_asof.py +++ b/pandas/tests/reshape/merge/test_merge_asof.py @@ -1047,9 +1047,9 @@ def test_on_float(self): tm.assert_frame_equal(result, expected) - def test_on_specialized_type(self, any_real_dtype): + def test_on_specialized_type(self, any_real_numpy_dtype): # see gh-13936 - dtype = np.dtype(any_real_dtype).type + dtype = np.dtype(any_real_numpy_dtype).type df1 = pd.DataFrame( {"value": [5, 2, 25, 100, 78, 120, 79], "symbol": list("ABCDEFG")}, @@ -1078,9 +1078,9 @@ def test_on_specialized_type(self, any_real_dtype): tm.assert_frame_equal(result, expected) - def test_on_specialized_type_by_int(self, any_real_dtype): + def test_on_specialized_type_by_int(self, any_real_numpy_dtype): # see gh-13936 - dtype = np.dtype(any_real_dtype).type + dtype = np.dtype(any_real_numpy_dtype).type df1 = pd.DataFrame( { @@ -1309,18 +1309,18 @@ def test_timedelta_tolerance_nearest(self): tm.assert_frame_equal(result, expected) - def test_int_type_tolerance(self, any_int_dtype): + def test_int_type_tolerance(self, any_int_numpy_dtype): # GH #28870 left = pd.DataFrame({"a": [0, 10, 20], "left_val": [1, 2, 3]}) right = pd.DataFrame({"a": [5, 15, 25], "right_val": [1, 2, 3]}) - left["a"] = left["a"].astype(any_int_dtype) - right["a"] = right["a"].astype(any_int_dtype) + left["a"] = left["a"].astype(any_int_numpy_dtype) + right["a"] = right["a"].astype(any_int_numpy_dtype) expected = pd.DataFrame( {"a": [0, 10, 20], "left_val": [1, 2, 3], "right_val": [np.nan, 1.0, 2.0]} ) - expected["a"] = expected["a"].astype(any_int_dtype) + expected["a"] = expected["a"].astype(any_int_numpy_dtype) result = merge_asof(left, right, on="a", tolerance=10) tm.assert_frame_equal(result, expected) diff --git a/pandas/tests/reshape/test_qcut.py b/pandas/tests/reshape/test_qcut.py index c12d28f6f1380e..6c4d14f1dede31 100644 --- a/pandas/tests/reshape/test_qcut.py +++ b/pandas/tests/reshape/test_qcut.py @@ -293,8 +293,8 @@ def test_qcut_bool_coercion_to_int(bins, box, compare): @pytest.mark.parametrize("q", [2, 5, 10]) -def test_qcut_nullable_integer(q, any_nullable_numeric_dtype): - arr = pd.array(np.arange(100), dtype=any_nullable_numeric_dtype) +def test_qcut_nullable_integer(q, any_numeric_ea_dtype): + arr = pd.array(np.arange(100), dtype=any_numeric_ea_dtype) arr[::2] = pd.NA result = qcut(arr, q) diff --git a/pandas/tests/series/indexing/test_getitem.py b/pandas/tests/series/indexing/test_getitem.py index 8793026ee74abf..da8de5c553f53a 100644 --- a/pandas/tests/series/indexing/test_getitem.py +++ b/pandas/tests/series/indexing/test_getitem.py @@ -360,10 +360,10 @@ def test_getitem_intlist_multiindex_numeric_level(self, dtype, box): with pytest.raises(KeyError, match="5"): ser[key] - def test_getitem_uint_array_key(self, uint_dtype): + def test_getitem_uint_array_key(self, any_unsigned_int_numpy_dtype): # GH #37218 ser = Series([1, 2, 3]) - key = np.array([4], dtype=uint_dtype) + key = np.array([4], dtype=any_unsigned_int_numpy_dtype) with pytest.raises(KeyError, match="4"): ser[key] diff --git a/pandas/tests/series/indexing/test_setitem.py b/pandas/tests/series/indexing/test_setitem.py index d720ba37fecaeb..0a82ecd2c551dc 100644 --- a/pandas/tests/series/indexing/test_setitem.py +++ b/pandas/tests/series/indexing/test_setitem.py @@ -263,19 +263,19 @@ def test_setitem_boolean_python_list(self, func): expected = Series(["a", "b", "c"]) tm.assert_series_equal(ser, expected) - def test_setitem_boolean_nullable_int_types(self, any_nullable_numeric_dtype): + def test_setitem_boolean_nullable_int_types(self, any_numeric_ea_dtype): # GH: 26468 - ser = Series([5, 6, 7, 8], dtype=any_nullable_numeric_dtype) - ser[ser > 6] = Series(range(4), dtype=any_nullable_numeric_dtype) - expected = Series([5, 6, 2, 3], dtype=any_nullable_numeric_dtype) + ser = Series([5, 6, 7, 8], dtype=any_numeric_ea_dtype) + ser[ser > 6] = Series(range(4), dtype=any_numeric_ea_dtype) + expected = Series([5, 6, 2, 3], dtype=any_numeric_ea_dtype) tm.assert_series_equal(ser, expected) - ser = Series([5, 6, 7, 8], dtype=any_nullable_numeric_dtype) - ser.loc[ser > 6] = Series(range(4), dtype=any_nullable_numeric_dtype) + ser = Series([5, 6, 7, 8], dtype=any_numeric_ea_dtype) + ser.loc[ser > 6] = Series(range(4), dtype=any_numeric_ea_dtype) tm.assert_series_equal(ser, expected) - ser = Series([5, 6, 7, 8], dtype=any_nullable_numeric_dtype) - loc_ser = Series(range(4), dtype=any_nullable_numeric_dtype) + ser = Series([5, 6, 7, 8], dtype=any_numeric_ea_dtype) + loc_ser = Series(range(4), dtype=any_numeric_ea_dtype) ser.loc[ser > 6] = loc_ser.loc[loc_ser > 1] tm.assert_series_equal(ser, expected) diff --git a/pandas/tests/series/indexing/test_where.py b/pandas/tests/series/indexing/test_where.py index 0c6b9bd9247591..ed1ba11c5fd55b 100644 --- a/pandas/tests/series/indexing/test_where.py +++ b/pandas/tests/series/indexing/test_where.py @@ -15,23 +15,26 @@ import pandas._testing as tm -def test_where_unsafe_int(sint_dtype): - s = Series(np.arange(10), dtype=sint_dtype) +def test_where_unsafe_int(any_signed_int_numpy_dtype): + s = Series(np.arange(10), dtype=any_signed_int_numpy_dtype) mask = s < 5 s[mask] = range(2, 7) - expected = Series(list(range(2, 7)) + list(range(5, 10)), dtype=sint_dtype) + expected = Series( + list(range(2, 7)) + list(range(5, 10)), + dtype=any_signed_int_numpy_dtype, + ) tm.assert_series_equal(s, expected) -def test_where_unsafe_float(float_dtype): - s = Series(np.arange(10), dtype=float_dtype) +def test_where_unsafe_float(float_numpy_dtype): + s = Series(np.arange(10), dtype=float_numpy_dtype) mask = s < 5 s[mask] = range(2, 7) data = list(range(2, 7)) + list(range(5, 10)) - expected = Series(data, dtype=float_dtype) + expected = Series(data, dtype=float_numpy_dtype) tm.assert_series_equal(s, expected) diff --git a/pandas/tests/series/methods/test_clip.py b/pandas/tests/series/methods/test_clip.py index 620f529b522aef..247f0d50772ce1 100644 --- a/pandas/tests/series/methods/test_clip.py +++ b/pandas/tests/series/methods/test_clip.py @@ -42,22 +42,16 @@ def test_clip_types_and_nulls(self): assert list(isna(s)) == list(isna(lower)) assert list(isna(s)) == list(isna(upper)) - def test_series_clipping_with_na_values( - self, any_nullable_numeric_dtype, nulls_fixture - ): + def test_series_clipping_with_na_values(self, any_numeric_ea_dtype, nulls_fixture): # Ensure that clipping method can handle NA values with out failing # GH#40581 - s = Series([nulls_fixture, 1.0, 3.0], dtype=any_nullable_numeric_dtype) + s = Series([nulls_fixture, 1.0, 3.0], dtype=any_numeric_ea_dtype) s_clipped_upper = s.clip(upper=2.0) s_clipped_lower = s.clip(lower=2.0) - expected_upper = Series( - [nulls_fixture, 1.0, 2.0], dtype=any_nullable_numeric_dtype - ) - expected_lower = Series( - [nulls_fixture, 2.0, 3.0], dtype=any_nullable_numeric_dtype - ) + expected_upper = Series([nulls_fixture, 1.0, 2.0], dtype=any_numeric_ea_dtype) + expected_lower = Series([nulls_fixture, 2.0, 3.0], dtype=any_numeric_ea_dtype) tm.assert_series_equal(s_clipped_upper, expected_upper) tm.assert_series_equal(s_clipped_lower, expected_lower) diff --git a/pandas/tests/series/methods/test_nlargest.py b/pandas/tests/series/methods/test_nlargest.py index 0efb0663a03274..d019092e211d62 100644 --- a/pandas/tests/series/methods/test_nlargest.py +++ b/pandas/tests/series/methods/test_nlargest.py @@ -166,20 +166,20 @@ def test_nlargest_n(self, n): expected = ser.sort_values().head(n) tm.assert_series_equal(result, expected) - def test_nlargest_boundary_integer(self, nselect_method, any_int_dtype): + def test_nlargest_boundary_integer(self, nselect_method, any_int_numpy_dtype): # GH#21426 - dtype_info = np.iinfo(any_int_dtype) + dtype_info = np.iinfo(any_int_numpy_dtype) min_val, max_val = dtype_info.min, dtype_info.max vals = [min_val, min_val + 1, max_val - 1, max_val] - assert_check_nselect_boundary(vals, any_int_dtype, nselect_method) + assert_check_nselect_boundary(vals, any_int_numpy_dtype, nselect_method) - def test_nlargest_boundary_float(self, nselect_method, float_dtype): + def test_nlargest_boundary_float(self, nselect_method, float_numpy_dtype): # GH#21426 - dtype_info = np.finfo(float_dtype) + dtype_info = np.finfo(float_numpy_dtype) min_val, max_val = dtype_info.min, dtype_info.max - min_2nd, max_2nd = np.nextafter([min_val, max_val], 0, dtype=float_dtype) + min_2nd, max_2nd = np.nextafter([min_val, max_val], 0, dtype=float_numpy_dtype) vals = [min_val, min_2nd, max_2nd, max_val] - assert_check_nselect_boundary(vals, float_dtype, nselect_method) + assert_check_nselect_boundary(vals, float_numpy_dtype, nselect_method) @pytest.mark.parametrize("dtype", ["datetime64[ns]", "timedelta64[ns]"]) def test_nlargest_boundary_datetimelike(self, nselect_method, dtype): @@ -212,9 +212,9 @@ def test_nlargest_boolean(self, data, expected): expected = Series(expected) tm.assert_series_equal(result, expected) - def test_nlargest_nullable(self, any_nullable_numeric_dtype): + def test_nlargest_nullable(self, any_numeric_ea_dtype): # GH#42816 - dtype = any_nullable_numeric_dtype + dtype = any_numeric_ea_dtype arr = np.random.randn(10).astype(dtype.lower(), copy=False) ser = Series(arr.copy(), dtype=dtype) diff --git a/pandas/tests/series/methods/test_replace.py b/pandas/tests/series/methods/test_replace.py index ef4b6174909c53..fb9c326bdafd97 100644 --- a/pandas/tests/series/methods/test_replace.py +++ b/pandas/tests/series/methods/test_replace.py @@ -211,12 +211,12 @@ def test_replace_with_dict_with_bool_keys(self): expected = pd.Series(["yes", False, "yes"]) tm.assert_series_equal(result, expected) - def test_replace_Int_with_na(self, any_nullable_int_dtype): + def test_replace_Int_with_na(self, any_int_ea_dtype): # GH 38267 - result = pd.Series([0, None], dtype=any_nullable_int_dtype).replace(0, pd.NA) - expected = pd.Series([pd.NA, pd.NA], dtype=any_nullable_int_dtype) + result = pd.Series([0, None], dtype=any_int_ea_dtype).replace(0, pd.NA) + expected = pd.Series([pd.NA, pd.NA], dtype=any_int_ea_dtype) tm.assert_series_equal(result, expected) - result = pd.Series([0, 1], dtype=any_nullable_int_dtype).replace(0, pd.NA) + result = pd.Series([0, 1], dtype=any_int_ea_dtype).replace(0, pd.NA) result.replace(1, pd.NA, inplace=True) tm.assert_series_equal(result, expected) diff --git a/pandas/tests/series/methods/test_round.py b/pandas/tests/series/methods/test_round.py index 7ab19a05159a49..6c40e364195512 100644 --- a/pandas/tests/series/methods/test_round.py +++ b/pandas/tests/series/methods/test_round.py @@ -16,40 +16,40 @@ def test_round(self, datetime_series): tm.assert_series_equal(result, expected) assert result.name == datetime_series.name - def test_round_numpy(self, any_float_allowed_nullable_dtype): + def test_round_numpy(self, any_float_dtype): # See GH#12600 - ser = Series([1.53, 1.36, 0.06], dtype=any_float_allowed_nullable_dtype) + ser = Series([1.53, 1.36, 0.06], dtype=any_float_dtype) out = np.round(ser, decimals=0) - expected = Series([2.0, 1.0, 0.0], dtype=any_float_allowed_nullable_dtype) + expected = Series([2.0, 1.0, 0.0], dtype=any_float_dtype) tm.assert_series_equal(out, expected) msg = "the 'out' parameter is not supported" with pytest.raises(ValueError, match=msg): np.round(ser, decimals=0, out=ser) - def test_round_numpy_with_nan(self, any_float_allowed_nullable_dtype): + def test_round_numpy_with_nan(self, any_float_dtype): # See GH#14197 - ser = Series([1.53, np.nan, 0.06], dtype=any_float_allowed_nullable_dtype) + ser = Series([1.53, np.nan, 0.06], dtype=any_float_dtype) with tm.assert_produces_warning(None): result = ser.round() - expected = Series([2.0, np.nan, 0.0], dtype=any_float_allowed_nullable_dtype) + expected = Series([2.0, np.nan, 0.0], dtype=any_float_dtype) tm.assert_series_equal(result, expected) - def test_round_builtin(self, any_float_allowed_nullable_dtype): + def test_round_builtin(self, any_float_dtype): ser = Series( [1.123, 2.123, 3.123], index=range(3), - dtype=any_float_allowed_nullable_dtype, + dtype=any_float_dtype, ) result = round(ser) expected_rounded0 = Series( - [1.0, 2.0, 3.0], index=range(3), dtype=any_float_allowed_nullable_dtype + [1.0, 2.0, 3.0], index=range(3), dtype=any_float_dtype ) tm.assert_series_equal(result, expected_rounded0) decimals = 2 expected_rounded = Series( - [1.12, 2.12, 3.12], index=range(3), dtype=any_float_allowed_nullable_dtype + [1.12, 2.12, 3.12], index=range(3), dtype=any_float_dtype ) result = round(ser, decimals) tm.assert_series_equal(result, expected_rounded) diff --git a/pandas/tests/series/test_constructors.py b/pandas/tests/series/test_constructors.py index 8525edc8dee801..523a8447e1fed9 100644 --- a/pandas/tests/series/test_constructors.py +++ b/pandas/tests/series/test_constructors.py @@ -726,29 +726,29 @@ def test_constructor_signed_int_overflow_deprecation(self): expected = Series([1, 200, 50], dtype="uint8") tm.assert_series_equal(ser, expected) - def test_constructor_unsigned_dtype_overflow(self, uint_dtype): + def test_constructor_unsigned_dtype_overflow(self, any_unsigned_int_numpy_dtype): # see gh-15832 msg = "Trying to coerce negative values to unsigned integers" with pytest.raises(OverflowError, match=msg): - Series([-1], dtype=uint_dtype) + Series([-1], dtype=any_unsigned_int_numpy_dtype) - def test_constructor_coerce_float_fail(self, any_int_dtype): + def test_constructor_coerce_float_fail(self, any_int_numpy_dtype): # see gh-15832 msg = "Trying to coerce float values to integers" with pytest.raises(ValueError, match=msg): - Series([1, 2, 3.5], dtype=any_int_dtype) + Series([1, 2, 3.5], dtype=any_int_numpy_dtype) - def test_constructor_coerce_float_valid(self, float_dtype): - s = Series([1, 2, 3.5], dtype=float_dtype) - expected = Series([1, 2, 3.5]).astype(float_dtype) + def test_constructor_coerce_float_valid(self, float_numpy_dtype): + s = Series([1, 2, 3.5], dtype=float_numpy_dtype) + expected = Series([1, 2, 3.5]).astype(float_numpy_dtype) tm.assert_series_equal(s, expected) - def test_constructor_invalid_coerce_ints_with_float_nan(self, any_int_dtype): + def test_constructor_invalid_coerce_ints_with_float_nan(self, any_int_numpy_dtype): # GH 22585 msg = "cannot convert float NaN to integer" with pytest.raises(ValueError, match=msg): - Series([1, 2, np.nan], dtype=any_int_dtype) + Series([1, 2, np.nan], dtype=any_int_numpy_dtype) def test_constructor_dtype_no_cast(self): # see gh-1572 diff --git a/pandas/tests/series/test_unary.py b/pandas/tests/series/test_unary.py index 67bb89b42a56d0..54fd467431489d 100644 --- a/pandas/tests/series/test_unary.py +++ b/pandas/tests/series/test_unary.py @@ -25,10 +25,10 @@ def test_invert(self): ], ) def test_all_numeric_unary_operators( - self, any_nullable_numeric_dtype, source, neg_target, abs_target + self, any_numeric_ea_dtype, source, neg_target, abs_target ): # GH38794 - dtype = any_nullable_numeric_dtype + dtype = any_numeric_ea_dtype ser = Series(source, dtype=dtype) neg_result, pos_result, abs_result = -ser, +ser, abs(ser) if dtype.startswith("U"): diff --git a/pandas/tests/test_algos.py b/pandas/tests/test_algos.py index b4836dffffa06f..ba587e28b8c3db 100644 --- a/pandas/tests/test_algos.py +++ b/pandas/tests/test_algos.py @@ -249,9 +249,9 @@ def test_complex_sorting(self): with pytest.raises(TypeError, match=msg): algos.factorize(x17[::-1], sort=True) - def test_numeric_dtype_factorize(self, any_real_dtype): + def test_numeric_dtype_factorize(self, any_real_numpy_dtype): # GH41132 - dtype = any_real_dtype + dtype = any_real_numpy_dtype data = np.array([1, 2, 2, 1], dtype=dtype) expected_codes = np.array([0, 1, 1, 0], dtype=np.intp) expected_uniques = np.array([1, 2], dtype=dtype) diff --git a/pandas/tests/util/test_assert_frame_equal.py b/pandas/tests/util/test_assert_frame_equal.py index 24ee6afb7c2545..faea0a54dc3306 100644 --- a/pandas/tests/util/test_assert_frame_equal.py +++ b/pandas/tests/util/test_assert_frame_equal.py @@ -307,15 +307,15 @@ def test_assert_frame_equal_columns_mixed_dtype(): tm.assert_frame_equal(df, df, check_like=True) -def test_frame_equal_extension_dtype(frame_or_series, any_nullable_numeric_dtype): +def test_frame_equal_extension_dtype(frame_or_series, any_numeric_ea_dtype): # GH#39410 - obj = frame_or_series([1, 2], dtype=any_nullable_numeric_dtype) + obj = frame_or_series([1, 2], dtype=any_numeric_ea_dtype) tm.assert_equal(obj, obj, check_exact=True) @pytest.mark.parametrize("indexer", [(0, 1), (1, 0)]) -def test_frame_equal_mixed_dtypes(frame_or_series, any_nullable_numeric_dtype, indexer): - dtypes = (any_nullable_numeric_dtype, "int64") +def test_frame_equal_mixed_dtypes(frame_or_series, any_numeric_ea_dtype, indexer): + dtypes = (any_numeric_ea_dtype, "int64") obj1 = frame_or_series([1, 2], dtype=dtypes[indexer[0]]) obj2 = frame_or_series([1, 2], dtype=dtypes[indexer[1]]) msg = r'(Series|DataFrame.iloc\[:, 0\] \(column name="0"\) classes) are different' diff --git a/pandas/tests/window/test_ewm.py b/pandas/tests/window/test_ewm.py index d2a3be88eb27b9..e3ea53121defac 100644 --- a/pandas/tests/window/test_ewm.py +++ b/pandas/tests/window/test_ewm.py @@ -221,11 +221,11 @@ def test_ewma_times_adjust_false_raises(): ], ], ) -def test_float_dtype_ewma(func, expected, float_dtype): +def test_float_dtype_ewma(func, expected, float_numpy_dtype): # GH#42452 df = DataFrame( - {0: range(5), 1: range(6, 11), 2: range(10, 20, 2)}, dtype=float_dtype + {0: range(5), 1: range(6, 11), 2: range(10, 20, 2)}, dtype=float_numpy_dtype ) e = df.ewm(alpha=0.5, axis=1) result = getattr(e, func)() diff --git a/pandas/tests/window/test_rolling.py b/pandas/tests/window/test_rolling.py index c49871bf3e1424..2edf22d96a9ba9 100644 --- a/pandas/tests/window/test_rolling.py +++ b/pandas/tests/window/test_rolling.py @@ -1456,10 +1456,13 @@ def test_rolling_zero_window(): tm.assert_series_equal(result, expected) -def test_rolling_float_dtype(float_dtype): +def test_rolling_float_dtype(float_numpy_dtype): # GH#42452 - df = DataFrame({"A": range(5), "B": range(10, 15)}, dtype=float_dtype) - expected = DataFrame({"A": [np.nan] * 5, "B": range(10, 20, 2)}, dtype=float_dtype) + df = DataFrame({"A": range(5), "B": range(10, 15)}, dtype=float_numpy_dtype) + expected = DataFrame( + {"A": [np.nan] * 5, "B": range(10, 20, 2)}, + dtype=float_numpy_dtype, + ) result = df.rolling(2, axis=1).sum() tm.assert_frame_equal(result, expected, check_dtype=False)