diff --git a/pandas/tests/base/test_misc.py b/pandas/tests/base/test_misc.py index 65e234e799353..f6a4396ca5be0 100644 --- a/pandas/tests/base/test_misc.py +++ b/pandas/tests/base/test_misc.py @@ -17,7 +17,6 @@ Index, Series, ) -import pandas._testing as tm def test_isnull_notnull_docstrings(): @@ -130,9 +129,13 @@ def test_memory_usage_components_series(series_with_simple_index): assert total_usage == non_index_usage + index_usage -@pytest.mark.parametrize("dtype", tm.NARROW_NP_DTYPES) -def test_memory_usage_components_narrow_series(dtype): - series = Series(range(5), dtype=dtype, index=[f"i-{i}" for i in range(5)], name="a") +def test_memory_usage_components_narrow_series(any_real_numpy_dtype): + series = Series( + range(5), + dtype=any_real_numpy_dtype, + index=[f"i-{i}" for i in range(5)], + name="a", + ) total_usage = series.memory_usage(index=True) non_index_usage = series.memory_usage(index=False) index_usage = series.index.memory_usage() diff --git a/pandas/tests/indexing/test_iloc.py b/pandas/tests/indexing/test_iloc.py index f36ddff223a9a..f9c6939654ea1 100644 --- a/pandas/tests/indexing/test_iloc.py +++ b/pandas/tests/indexing/test_iloc.py @@ -75,8 +75,7 @@ class TestiLocBaseIndependent: np.asarray([0, 1, 2]), ], ) - @pytest.mark.parametrize("indexer", [tm.loc, tm.iloc]) - def test_iloc_setitem_fullcol_categorical(self, indexer, key): + def test_iloc_setitem_fullcol_categorical(self, indexer_li, key): frame = DataFrame({0: range(3)}, dtype=object) cat = Categorical(["alpha", "beta", "gamma"]) @@ -86,7 +85,7 @@ def test_iloc_setitem_fullcol_categorical(self, indexer, key): df = frame.copy() orig_vals = df.values - indexer(df)[key, 0] = cat + indexer_li(df)[key, 0] = cat expected = DataFrame({0: cat}).astype(object) assert np.shares_memory(df[0].values, orig_vals) @@ -102,7 +101,7 @@ def test_iloc_setitem_fullcol_categorical(self, indexer, key): # we retain the object dtype. frame = DataFrame({0: np.array([0, 1, 2], dtype=object), 1: range(3)}) df = frame.copy() - indexer(df)[key, 0] = cat + indexer_li(df)[key, 0] = cat expected = DataFrame({0: Series(cat.astype(object), dtype=object), 1: range(3)}) tm.assert_frame_equal(df, expected) @@ -985,8 +984,7 @@ def test_iloc_setitem_empty_frame_raises_with_3d_ndarray(self): with pytest.raises(ValueError, match=msg): obj.iloc[nd3] = 0 - @pytest.mark.parametrize("indexer", [tm.loc, tm.iloc]) - def test_iloc_getitem_read_only_values(self, indexer): + def test_iloc_getitem_read_only_values(self, indexer_li): # GH#10043 this is fundamentally a test for iloc, but test loc while # we're here rw_array = np.eye(10) @@ -996,10 +994,12 @@ def test_iloc_getitem_read_only_values(self, indexer): ro_array.setflags(write=False) ro_df = DataFrame(ro_array) - tm.assert_frame_equal(indexer(rw_df)[[1, 2, 3]], indexer(ro_df)[[1, 2, 3]]) - tm.assert_frame_equal(indexer(rw_df)[[1]], indexer(ro_df)[[1]]) - tm.assert_series_equal(indexer(rw_df)[1], indexer(ro_df)[1]) - tm.assert_frame_equal(indexer(rw_df)[1:3], indexer(ro_df)[1:3]) + tm.assert_frame_equal( + indexer_li(rw_df)[[1, 2, 3]], indexer_li(ro_df)[[1, 2, 3]] + ) + tm.assert_frame_equal(indexer_li(rw_df)[[1]], indexer_li(ro_df)[[1]]) + tm.assert_series_equal(indexer_li(rw_df)[1], indexer_li(ro_df)[1]) + tm.assert_frame_equal(indexer_li(rw_df)[1:3], indexer_li(ro_df)[1:3]) def test_iloc_getitem_readonly_key(self): # GH#17192 iloc with read-only array raising TypeError diff --git a/pandas/tests/io/parser/dtypes/test_dtypes_basic.py b/pandas/tests/io/parser/dtypes/test_dtypes_basic.py index ce02e752fb90b..70fd0b02cc79d 100644 --- a/pandas/tests/io/parser/dtypes/test_dtypes_basic.py +++ b/pandas/tests/io/parser/dtypes/test_dtypes_basic.py @@ -132,15 +132,12 @@ def test_dtype_with_converters(all_parsers): tm.assert_frame_equal(result, expected) -@pytest.mark.parametrize( - "dtype", list(np.typecodes["AllInteger"] + np.typecodes["Float"]) -) -def test_numeric_dtype(all_parsers, dtype): +def test_numeric_dtype(all_parsers, any_real_numpy_dtype): data = "0\n1" parser = all_parsers - expected = DataFrame([0, 1], dtype=dtype) + expected = DataFrame([0, 1], dtype=any_real_numpy_dtype) - result = parser.read_csv(StringIO(data), header=None, dtype=dtype) + result = parser.read_csv(StringIO(data), header=None, dtype=any_real_numpy_dtype) tm.assert_frame_equal(expected, result) diff --git a/pandas/tests/reductions/test_reductions.py b/pandas/tests/reductions/test_reductions.py index fcb5b65e59402..4cdd50d70d078 100644 --- a/pandas/tests/reductions/test_reductions.py +++ b/pandas/tests/reductions/test_reductions.py @@ -1417,13 +1417,10 @@ def test_mode_empty(self, dropna, expected): (False, [1, 1, 1, 2, 3, 3, 3], [1, 3]), ], ) - @pytest.mark.parametrize( - "dt", list(np.typecodes["AllInteger"] + np.typecodes["Float"]) - ) - def test_mode_numerical(self, dropna, data, expected, dt): - s = Series(data, dtype=dt) + def test_mode_numerical(self, dropna, data, expected, any_real_numpy_dtype): + s = Series(data, dtype=any_real_numpy_dtype) result = s.mode(dropna) - expected = Series(expected, dtype=dt) + expected = Series(expected, dtype=any_real_numpy_dtype) tm.assert_series_equal(result, expected) @pytest.mark.parametrize("dropna, expected", [(True, [1.0]), (False, [1, np.nan])]) diff --git a/pandas/tests/reshape/merge/test_merge.py b/pandas/tests/reshape/merge/test_merge.py index 21a38c43f4294..3b37ffa7baa82 100644 --- a/pandas/tests/reshape/merge/test_merge.py +++ b/pandas/tests/reshape/merge/test_merge.py @@ -1488,12 +1488,9 @@ def test_different(self, right_vals): result = merge(left, right, on="A") assert is_object_dtype(result.A.dtype) - @pytest.mark.parametrize( - "d1", [np.int64, np.int32, np.intc, np.int16, np.int8, np.uint8] - ) @pytest.mark.parametrize("d2", [np.int64, np.float64, np.float32, np.float16]) - def test_join_multi_dtypes(self, d1, d2): - dtype1 = np.dtype(d1) + def test_join_multi_dtypes(self, any_int_numpy_dtype, d2): + dtype1 = np.dtype(any_int_numpy_dtype) dtype2 = np.dtype(d2) left = DataFrame( diff --git a/pandas/tests/scalar/timestamp/test_formats.py b/pandas/tests/scalar/timestamp/test_formats.py index d7160597ea6d6..6a578b0a9eb09 100644 --- a/pandas/tests/scalar/timestamp/test_formats.py +++ b/pandas/tests/scalar/timestamp/test_formats.py @@ -88,9 +88,9 @@ def test_isoformat(ts, timespec, expected_iso): class TestTimestampRendering: - timezones = ["UTC", "Asia/Tokyo", "US/Eastern", "dateutil/US/Pacific"] - - @pytest.mark.parametrize("tz", timezones) + @pytest.mark.parametrize( + "tz", ["UTC", "Asia/Tokyo", "US/Eastern", "dateutil/US/Pacific"] + ) @pytest.mark.parametrize("freq", ["D", "M", "S", "N"]) @pytest.mark.parametrize( "date", ["2014-03-07", "2014-01-01 09:00", "2014-01-01 00:00:00.000000001"] diff --git a/pandas/tests/series/methods/test_astype.py b/pandas/tests/series/methods/test_astype.py index 46f55fff91e41..4d2cd2ba963fd 100644 --- a/pandas/tests/series/methods/test_astype.py +++ b/pandas/tests/series/methods/test_astype.py @@ -342,10 +342,9 @@ def test_astype_ignores_errors_for_extension_dtypes(self, data, dtype, errors): with pytest.raises((ValueError, TypeError), match=msg): ser.astype(float, errors=errors) - @pytest.mark.parametrize("dtype", [np.float16, np.float32, np.float64]) - def test_astype_from_float_to_str(self, dtype): + def test_astype_from_float_to_str(self, any_float_dtype): # https://github.com/pandas-dev/pandas/issues/36451 - ser = Series([0.1], dtype=dtype) + ser = Series([0.1], dtype=any_float_dtype) result = ser.astype(str) expected = Series(["0.1"], dtype=object) tm.assert_series_equal(result, expected) @@ -374,21 +373,19 @@ def test_astype(self, dtype): assert as_typed.name == ser.name @pytest.mark.parametrize("value", [np.nan, np.inf]) - @pytest.mark.parametrize("dtype", [np.int32, np.int64]) - def test_astype_cast_nan_inf_int(self, dtype, value): + def test_astype_cast_nan_inf_int(self, any_int_numpy_dtype, value): # gh-14265: check NaN and inf raise error when converting to int msg = "Cannot convert non-finite values \\(NA or inf\\) to integer" ser = Series([value]) with pytest.raises(ValueError, match=msg): - ser.astype(dtype) + ser.astype(any_int_numpy_dtype) - @pytest.mark.parametrize("dtype", [int, np.int8, np.int64]) - def test_astype_cast_object_int_fail(self, dtype): + def test_astype_cast_object_int_fail(self, any_int_numpy_dtype): arr = Series(["car", "house", "tree", "1"]) msg = r"invalid literal for int\(\) with base 10: 'car'" with pytest.raises(ValueError, match=msg): - arr.astype(dtype) + arr.astype(any_int_numpy_dtype) def test_astype_float_to_uint_negatives_raise( self, float_numpy_dtype, any_unsigned_int_numpy_dtype diff --git a/pandas/tests/series/methods/test_compare.py b/pandas/tests/series/methods/test_compare.py index fe2016a245ec7..304045e46702b 100644 --- a/pandas/tests/series/methods/test_compare.py +++ b/pandas/tests/series/methods/test_compare.py @@ -5,15 +5,14 @@ import pandas._testing as tm -@pytest.mark.parametrize("align_axis", [0, 1, "index", "columns"]) -def test_compare_axis(align_axis): +def test_compare_axis(axis): # GH#30429 s1 = pd.Series(["a", "b", "c"]) s2 = pd.Series(["x", "b", "z"]) - result = s1.compare(s2, align_axis=align_axis) + result = s1.compare(s2, align_axis=axis) - if align_axis in (1, "columns"): + if axis in (1, "columns"): indices = pd.Index([0, 2]) columns = pd.Index(["self", "other"]) expected = pd.DataFrame( diff --git a/pandas/tests/series/methods/test_cov_corr.py b/pandas/tests/series/methods/test_cov_corr.py index a369145b4e884..bd60265582652 100644 --- a/pandas/tests/series/methods/test_cov_corr.py +++ b/pandas/tests/series/methods/test_cov_corr.py @@ -56,11 +56,10 @@ def test_cov_ddof(self, test_ddof, dtype): class TestSeriesCorr: - @pytest.mark.parametrize("dtype", ["float64", "Float64"]) - def test_corr(self, datetime_series, dtype): + def test_corr(self, datetime_series, any_float_dtype): stats = pytest.importorskip("scipy.stats") - datetime_series = datetime_series.astype(dtype) + datetime_series = datetime_series.astype(any_float_dtype) # full overlap tm.assert_almost_equal(datetime_series.corr(datetime_series), 1) diff --git a/pandas/tests/series/methods/test_fillna.py b/pandas/tests/series/methods/test_fillna.py index 293259661cd9a..f38e4a622cffa 100644 --- a/pandas/tests/series/methods/test_fillna.py +++ b/pandas/tests/series/methods/test_fillna.py @@ -838,12 +838,11 @@ def test_fillna_categorical_raises(self): ser.fillna(DataFrame({1: ["a"], 3: ["b"]})) @pytest.mark.parametrize("dtype", [float, "float32", "float64"]) - @pytest.mark.parametrize("fill_type", tm.ALL_REAL_NUMPY_DTYPES) @pytest.mark.parametrize("scalar", [True, False]) - def test_fillna_float_casting(self, dtype, fill_type, scalar): + def test_fillna_float_casting(self, dtype, any_real_numpy_dtype, scalar): # GH-43424 ser = Series([np.nan, 1.2], dtype=dtype) - fill_values = Series([2, 2], dtype=fill_type) + fill_values = Series([2, 2], dtype=any_real_numpy_dtype) if scalar: fill_values = fill_values.dtype.type(2) diff --git a/pandas/tests/test_algos.py b/pandas/tests/test_algos.py index 02cd7b77c9b7d..de0338b39d91a 100644 --- a/pandas/tests/test_algos.py +++ b/pandas/tests/test_algos.py @@ -1795,11 +1795,10 @@ def test_scipy_compat(self, arr): exp[mask] = np.nan tm.assert_almost_equal(result, exp) - @pytest.mark.parametrize("dtype", np.typecodes["AllInteger"]) - def test_basic(self, writable, dtype): + def test_basic(self, writable, any_int_numpy_dtype): exp = np.array([1, 2], dtype=np.float64) - data = np.array([1, 100], dtype=dtype) + data = np.array([1, 100], dtype=any_int_numpy_dtype) data.setflags(write=writable) ser = Series(data) result = algos.rank(ser) @@ -1836,8 +1835,7 @@ def test_no_mode(self): exp = Series([], dtype=np.float64, index=Index([], dtype=int)) tm.assert_numpy_array_equal(algos.mode(np.array([])), exp.values) - @pytest.mark.parametrize("dt", np.typecodes["AllInteger"] + np.typecodes["Float"]) - def test_mode_single(self, dt): + def test_mode_single(self, any_real_numpy_dtype): # GH 15714 exp_single = [1] data_single = [1] @@ -1845,13 +1843,13 @@ def test_mode_single(self, dt): exp_multi = [1] data_multi = [1, 1] - ser = Series(data_single, dtype=dt) - exp = Series(exp_single, dtype=dt) + ser = Series(data_single, dtype=any_real_numpy_dtype) + exp = Series(exp_single, dtype=any_real_numpy_dtype) tm.assert_numpy_array_equal(algos.mode(ser.values), exp.values) tm.assert_series_equal(ser.mode(), exp) - ser = Series(data_multi, dtype=dt) - exp = Series(exp_multi, dtype=dt) + ser = Series(data_multi, dtype=any_real_numpy_dtype) + exp = Series(exp_multi, dtype=any_real_numpy_dtype) tm.assert_numpy_array_equal(algos.mode(ser.values), exp.values) tm.assert_series_equal(ser.mode(), exp) @@ -1862,21 +1860,20 @@ def test_mode_obj_int(self): exp = Series(["a", "b", "c"], dtype=object) tm.assert_numpy_array_equal(algos.mode(exp.values), exp.values) - @pytest.mark.parametrize("dt", np.typecodes["AllInteger"] + np.typecodes["Float"]) - def test_number_mode(self, dt): + def test_number_mode(self, any_real_numpy_dtype): exp_single = [1] data_single = [1] * 5 + [2] * 3 exp_multi = [1, 3] data_multi = [1] * 5 + [2] * 3 + [3] * 5 - ser = Series(data_single, dtype=dt) - exp = Series(exp_single, dtype=dt) + ser = Series(data_single, dtype=any_real_numpy_dtype) + exp = Series(exp_single, dtype=any_real_numpy_dtype) tm.assert_numpy_array_equal(algos.mode(ser.values), exp.values) tm.assert_series_equal(ser.mode(), exp) - ser = Series(data_multi, dtype=dt) - exp = Series(exp_multi, dtype=dt) + ser = Series(data_multi, dtype=any_real_numpy_dtype) + exp = Series(exp_multi, dtype=any_real_numpy_dtype) tm.assert_numpy_array_equal(algos.mode(ser.values), exp.values) tm.assert_series_equal(ser.mode(), exp) diff --git a/pandas/tests/util/test_assert_extension_array_equal.py b/pandas/tests/util/test_assert_extension_array_equal.py index 674e9307d8bb9..5d82ae9af0e95 100644 --- a/pandas/tests/util/test_assert_extension_array_equal.py +++ b/pandas/tests/util/test_assert_extension_array_equal.py @@ -108,11 +108,10 @@ def test_assert_extension_array_equal_non_extension_array(side): tm.assert_extension_array_equal(*args) -@pytest.mark.parametrize("right_dtype", ["Int32", "int64"]) -def test_assert_extension_array_equal_ignore_dtype_mismatch(right_dtype): +def test_assert_extension_array_equal_ignore_dtype_mismatch(any_int_dtype): # https://github.com/pandas-dev/pandas/issues/35715 left = array([1, 2, 3], dtype="Int64") - right = array([1, 2, 3], dtype=right_dtype) + right = array([1, 2, 3], dtype=any_int_dtype) tm.assert_extension_array_equal(left, right, check_dtype=False) diff --git a/pandas/tests/util/test_assert_series_equal.py b/pandas/tests/util/test_assert_series_equal.py index c4ffc197298f0..70efa4293c46d 100644 --- a/pandas/tests/util/test_assert_series_equal.py +++ b/pandas/tests/util/test_assert_series_equal.py @@ -106,12 +106,11 @@ def test_series_not_equal_metadata_mismatch(kwargs): @pytest.mark.parametrize("data1,data2", [(0.12345, 0.12346), (0.1235, 0.1236)]) -@pytest.mark.parametrize("dtype", ["float32", "float64", "Float32"]) @pytest.mark.parametrize("decimals", [0, 1, 2, 3, 5, 10]) -def test_less_precise(data1, data2, dtype, decimals): +def test_less_precise(data1, data2, any_float_dtype, decimals): rtol = 10**-decimals - s1 = Series([data1], dtype=dtype) - s2 = Series([data2], dtype=dtype) + s1 = Series([data1], dtype=any_float_dtype) + s2 = Series([data2], dtype=any_float_dtype) if decimals in (5, 10) or (decimals >= 3 and abs(data1 - data2) >= 0.0005): msg = "Series values are different" diff --git a/pandas/tests/window/test_rolling_functions.py b/pandas/tests/window/test_rolling_functions.py index 5906ff52db098..f77a98ae9a7d9 100644 --- a/pandas/tests/window/test_rolling_functions.py +++ b/pandas/tests/window/test_rolling_functions.py @@ -471,20 +471,19 @@ def test_rolling_median_memory_error(): ).median() -@pytest.mark.parametrize( - "data_type", - [np.dtype(f"f{width}") for width in [4, 8]] - + [np.dtype(f"{sign}{width}") for width in [1, 2, 4, 8] for sign in "ui"], -) -def test_rolling_min_max_numeric_types(data_type): +def test_rolling_min_max_numeric_types(any_real_numpy_dtype): # GH12373 # Just testing that these don't throw exceptions and that # the return type is float64. Other tests will cover quantitative # correctness - result = DataFrame(np.arange(20, dtype=data_type)).rolling(window=5).max() + result = ( + DataFrame(np.arange(20, dtype=any_real_numpy_dtype)).rolling(window=5).max() + ) assert result.dtypes[0] == np.dtype("f8") - result = DataFrame(np.arange(20, dtype=data_type)).rolling(window=5).min() + result = ( + DataFrame(np.arange(20, dtype=any_real_numpy_dtype)).rolling(window=5).min() + ) assert result.dtypes[0] == np.dtype("f8")