diff --git a/pandas/tests/resample/test_resample_api.py b/pandas/tests/resample/test_resample_api.py index ba0b93d0b06f4..dbd28868b81b1 100644 --- a/pandas/tests/resample/test_resample_api.py +++ b/pandas/tests/resample/test_resample_api.py @@ -16,38 +16,43 @@ import pandas._testing as tm from pandas.core.indexes.datetimes import date_range -dti = date_range(start=datetime(2005, 1, 1), end=datetime(2005, 1, 10), freq="Min") -test_series = Series(np.random.rand(len(dti)), dti) -_test_frame = DataFrame({"A": test_series, "B": test_series, "C": np.arange(len(dti))}) +@pytest.fixture +def dti(): + return date_range(start=datetime(2005, 1, 1), end=datetime(2005, 1, 10), freq="Min") + + +@pytest.fixture +def _test_series(dti): + return Series(np.random.rand(len(dti)), dti) @pytest.fixture -def test_frame(): - return _test_frame.copy() +def test_frame(dti, _test_series): + return DataFrame({"A": _test_series, "B": _test_series, "C": np.arange(len(dti))}) -def test_str(): - r = test_series.resample("H") +def test_str(_test_series): + r = _test_series.resample("H") assert ( "DatetimeIndexResampler [freq=, axis=0, closed=left, " "label=left, convention=start, origin=start_day]" in str(r) ) - r = test_series.resample("H", origin="2000-01-01") + r = _test_series.resample("H", origin="2000-01-01") assert ( "DatetimeIndexResampler [freq=, axis=0, closed=left, " "label=left, convention=start, origin=2000-01-01 00:00:00]" in str(r) ) -def test_api(): - r = test_series.resample("H") +def test_api(_test_series): + r = _test_series.resample("H") result = r.mean() assert isinstance(result, Series) assert len(result) == 217 - r = test_series.to_frame().resample("H") + r = _test_series.to_frame().resample("H") result = r.mean() assert isinstance(result, DataFrame) assert len(result) == 217 @@ -116,11 +121,11 @@ def test_resample_group_keys(): tm.assert_frame_equal(result, expected) -def test_pipe(test_frame): +def test_pipe(test_frame, _test_series): # GH17905 # series - r = test_series.resample("H") + r = _test_series.resample("H") expected = r.max() - r.mean() result = r.pipe(lambda x: x.max() - x.mean()) tm.assert_series_equal(result, expected) @@ -261,9 +266,9 @@ def test_combined_up_downsampling_of_irregular(): tm.assert_series_equal(result, expected) -def test_transform_series(): - r = test_series.resample("20min") - expected = test_series.groupby(pd.Grouper(freq="20min")).transform("mean") +def test_transform_series(_test_series): + r = _test_series.resample("20min") + expected = _test_series.groupby(pd.Grouper(freq="20min")).transform("mean") result = r.transform("mean") tm.assert_series_equal(result, expected) @@ -319,17 +324,17 @@ def test_fillna(): ], ids=["resample", "groupby"], ) -def test_apply_without_aggregation(func): +def test_apply_without_aggregation(func, _test_series): # both resample and groupby should work w/o aggregation - t = func(test_series) + t = func(_test_series) result = t.apply(lambda x: x) - tm.assert_series_equal(result, test_series) + tm.assert_series_equal(result, _test_series) -def test_apply_without_aggregation2(): - grouped = test_series.to_frame(name="foo").resample("20min", group_keys=False) +def test_apply_without_aggregation2(_test_series): + grouped = _test_series.to_frame(name="foo").resample("20min", group_keys=False) result = grouped["foo"].apply(lambda x: x) - tm.assert_series_equal(result, test_series.rename("foo")) + tm.assert_series_equal(result, _test_series.rename("foo")) def test_agg_consistency(): @@ -1010,13 +1015,13 @@ def test_df_axis_param_depr(): df.resample("M", axis=0) -def test_series_axis_param_depr(): +def test_series_axis_param_depr(_test_series): warning_msg = ( "The 'axis' keyword in Series.resample is " "deprecated and will be removed in a future version." ) with tm.assert_produces_warning(FutureWarning, match=warning_msg): - test_series.resample("H", axis=0) + _test_series.resample("H", axis=0) def test_resample_empty(): diff --git a/pandas/tests/resample/test_resampler_grouper.py b/pandas/tests/resample/test_resampler_grouper.py index 1682edb42915d..df14a5bc374c6 100644 --- a/pandas/tests/resample/test_resampler_grouper.py +++ b/pandas/tests/resample/test_resampler_grouper.py @@ -17,10 +17,13 @@ import pandas._testing as tm from pandas.core.indexes.datetimes import date_range -test_frame = DataFrame( - {"A": [1] * 20 + [2] * 12 + [3] * 8, "B": np.arange(40)}, - index=date_range("1/1/2000", freq="s", periods=40), -) + +@pytest.fixture +def test_frame(): + return DataFrame( + {"A": [1] * 20 + [2] * 12 + [3] * 8, "B": np.arange(40)}, + index=date_range("1/1/2000", freq="s", periods=40), + ) @async_mark() @@ -85,7 +88,7 @@ def f_1(x): tm.assert_frame_equal(result, expected) -def test_getitem(): +def test_getitem(test_frame): g = test_frame.groupby("A") expected = g.B.apply(lambda x: x.resample("2s").mean()) @@ -217,7 +220,7 @@ def test_nearest(): "ohlc", ], ) -def test_methods(f): +def test_methods(f, test_frame): g = test_frame.groupby("A") r = g.resample("2s") @@ -226,7 +229,7 @@ def test_methods(f): tm.assert_equal(result, expected) -def test_methods_nunique(): +def test_methods_nunique(test_frame): # series only g = test_frame.groupby("A") r = g.resample("2s") @@ -236,7 +239,7 @@ def test_methods_nunique(): @pytest.mark.parametrize("f", ["std", "var"]) -def test_methods_std_var(f): +def test_methods_std_var(f, test_frame): g = test_frame.groupby("A") r = g.resample("2s") result = getattr(r, f)(ddof=1) @@ -244,7 +247,7 @@ def test_methods_std_var(f): tm.assert_frame_equal(result, expected) -def test_apply(): +def test_apply(test_frame): g = test_frame.groupby("A") r = g.resample("2s") @@ -342,7 +345,7 @@ def test_resample_groupby_with_label(): tm.assert_frame_equal(result, expected) -def test_consistency_with_window(): +def test_consistency_with_window(test_frame): # consistent return values with window df = test_frame expected = Index([1, 2, 3], name="A") diff --git a/pandas/tests/resample/test_time_grouper.py b/pandas/tests/resample/test_time_grouper.py index debfb48c2b39c..a5fb48f801522 100644 --- a/pandas/tests/resample/test_time_grouper.py +++ b/pandas/tests/resample/test_time_grouper.py @@ -14,10 +14,13 @@ from pandas.core.groupby.grouper import Grouper from pandas.core.indexes.datetimes import date_range -test_series = Series(np.random.randn(1000), index=date_range("1/1/2000", periods=1000)) +@pytest.fixture +def test_series(): + return Series(np.random.randn(1000), index=date_range("1/1/2000", periods=1000)) -def test_apply(): + +def test_apply(test_series): grouper = Grouper(freq="A", label="right", closed="right") grouped = test_series.groupby(grouper) @@ -33,7 +36,7 @@ def f(x): tm.assert_series_equal(applied, expected) -def test_count(): +def test_count(test_series): test_series[::3] = np.nan expected = test_series.groupby(lambda x: x.year).count() @@ -48,7 +51,7 @@ def test_count(): tm.assert_series_equal(result, expected) -def test_numpy_reduction(): +def test_numpy_reduction(test_series): result = test_series.resample("A", closed="right").prod() expected = test_series.groupby(lambda x: x.year).agg(np.prod) diff --git a/pandas/tests/reshape/concat/test_append_common.py b/pandas/tests/reshape/concat/test_append_common.py index 2d84de8145111..948545320a31a 100644 --- a/pandas/tests/reshape/concat/test_append_common.py +++ b/pandas/tests/reshape/concat/test_append_common.py @@ -10,37 +10,46 @@ ) import pandas._testing as tm -dt_data = [ - pd.Timestamp("2011-01-01"), - pd.Timestamp("2011-01-02"), - pd.Timestamp("2011-01-03"), -] -tz_data = [ - pd.Timestamp("2011-01-01", tz="US/Eastern"), - pd.Timestamp("2011-01-02", tz="US/Eastern"), - pd.Timestamp("2011-01-03", tz="US/Eastern"), -] -td_data = [ - pd.Timedelta("1 days"), - pd.Timedelta("2 days"), - pd.Timedelta("3 days"), -] -period_data = [ - pd.Period("2011-01", freq="M"), - pd.Period("2011-02", freq="M"), - pd.Period("2011-03", freq="M"), -] -data_dict = { - "bool": [True, False, True], - "int64": [1, 2, 3], - "float64": [1.1, np.nan, 3.3], - "category": Categorical(["X", "Y", "Z"]), - "object": ["a", "b", "c"], - "datetime64[ns]": dt_data, - "datetime64[ns, US/Eastern]": tz_data, - "timedelta64[ns]": td_data, - "period[M]": period_data, -} + +@pytest.fixture( + params=list( + { + "bool": [True, False, True], + "int64": [1, 2, 3], + "float64": [1.1, np.nan, 3.3], + "category": Categorical(["X", "Y", "Z"]), + "object": ["a", "b", "c"], + "datetime64[ns]": [ + pd.Timestamp("2011-01-01"), + pd.Timestamp("2011-01-02"), + pd.Timestamp("2011-01-03"), + ], + "datetime64[ns, US/Eastern]": [ + pd.Timestamp("2011-01-01", tz="US/Eastern"), + pd.Timestamp("2011-01-02", tz="US/Eastern"), + pd.Timestamp("2011-01-03", tz="US/Eastern"), + ], + "timedelta64[ns]": [ + pd.Timedelta("1 days"), + pd.Timedelta("2 days"), + pd.Timedelta("3 days"), + ], + "period[M]": [ + pd.Period("2011-01", freq="M"), + pd.Period("2011-02", freq="M"), + pd.Period("2011-03", freq="M"), + ], + }.items() + ) +) +def item(request): + key, data = request.param + return key, data + + +@pytest.fixture +def item2(item): + return item class TestConcatAppendCommon: @@ -48,13 +57,6 @@ class TestConcatAppendCommon: Test common dtype coercion rules between concat and append. """ - @pytest.fixture(params=sorted(data_dict.keys())) - def item(self, request): - key = request.param - return key, data_dict[key] - - item2 = item - def test_dtypes(self, item, index_or_series): # to confirm test case covers intended dtypes typ, vals = item diff --git a/pandas/tests/series/methods/test_argsort.py b/pandas/tests/series/methods/test_argsort.py index 1fbc9ed787e11..e1d64795e235d 100644 --- a/pandas/tests/series/methods/test_argsort.py +++ b/pandas/tests/series/methods/test_argsort.py @@ -10,10 +10,11 @@ class TestSeriesArgsort: - def _check_accum_op(self, name, ser, check_dtype=True): - func = getattr(np, name) + def test_argsort_numpy(self, datetime_series): + ser = datetime_series + func = np.argsort tm.assert_numpy_array_equal( - func(ser).values, func(np.array(ser)), check_dtype=check_dtype + func(ser).values, func(np.array(ser)), check_dtype=False ) # with missing values @@ -26,7 +27,6 @@ def _check_accum_op(self, name, ser, check_dtype=True): tm.assert_numpy_array_equal(result.values, expected, check_dtype=False) def test_argsort(self, datetime_series): - self._check_accum_op("argsort", datetime_series, check_dtype=False) argsorted = datetime_series.argsort() assert issubclass(argsorted.dtype.type, np.integer) diff --git a/pandas/tests/series/methods/test_convert_dtypes.py b/pandas/tests/series/methods/test_convert_dtypes.py index b0f5093e4951d..f2ac5f1086625 100644 --- a/pandas/tests/series/methods/test_convert_dtypes.py +++ b/pandas/tests/series/methods/test_convert_dtypes.py @@ -12,149 +12,162 @@ # this default. Those overrides are defined as a dict with (keyword, val) as # dictionary key. In case of multiple items, the last override takes precedence. -test_cases = [ - ( - # data - [1, 2, 3], - # original dtype - np.dtype("int32"), - # default expected dtype - "Int32", - # exceptions on expected dtype - {("convert_integer", False): np.dtype("int32")}, - ), - ( - [1, 2, 3], - np.dtype("int64"), - "Int64", - {("convert_integer", False): np.dtype("int64")}, - ), - ( - ["x", "y", "z"], - np.dtype("O"), - pd.StringDtype(), - {("convert_string", False): np.dtype("O")}, - ), - ( - [True, False, np.nan], - np.dtype("O"), - pd.BooleanDtype(), - {("convert_boolean", False): np.dtype("O")}, - ), - ( - ["h", "i", np.nan], - np.dtype("O"), - pd.StringDtype(), - {("convert_string", False): np.dtype("O")}, - ), - ( # GH32117 - ["h", "i", 1], - np.dtype("O"), - np.dtype("O"), - {}, - ), - ( - [10, np.nan, 20], - np.dtype("float"), - "Int64", - { - ("convert_integer", False, "convert_floating", True): "Float64", - ("convert_integer", False, "convert_floating", False): np.dtype("float"), - }, - ), - ( - [np.nan, 100.5, 200], - np.dtype("float"), - "Float64", - {("convert_floating", False): np.dtype("float")}, - ), - ( - [3, 4, 5], - "Int8", - "Int8", - {}, - ), - ( - [[1, 2], [3, 4], [5]], - None, - np.dtype("O"), - {}, - ), - ( - [4, 5, 6], - np.dtype("uint32"), - "UInt32", - {("convert_integer", False): np.dtype("uint32")}, - ), - ( - [-10, 12, 13], - np.dtype("i1"), - "Int8", - {("convert_integer", False): np.dtype("i1")}, - ), - ( - [1.2, 1.3], - np.dtype("float32"), - "Float32", - {("convert_floating", False): np.dtype("float32")}, - ), - ( - [1, 2.0], - object, - "Int64", - { - ("convert_integer", False): "Float64", - ("convert_integer", False, "convert_floating", False): np.dtype("float"), - ("infer_objects", False): np.dtype("object"), - }, - ), - ( - [1, 2.5], - object, - "Float64", - { - ("convert_floating", False): np.dtype("float"), - ("infer_objects", False): np.dtype("object"), - }, - ), - (["a", "b"], pd.CategoricalDtype(), pd.CategoricalDtype(), {}), - ( - pd.to_datetime(["2020-01-14 10:00", "2020-01-15 11:11"]), - pd.DatetimeTZDtype(tz="UTC"), - pd.DatetimeTZDtype(tz="UTC"), - {}, - ), - ( - pd.to_datetime(["2020-01-14 10:00", "2020-01-15 11:11"]), - "datetime64[ns]", - np.dtype("datetime64[ns]"), - {}, - ), - ( - pd.to_datetime(["2020-01-14 10:00", "2020-01-15 11:11"]), - object, - np.dtype("datetime64[ns]"), - {("infer_objects", False): np.dtype("object")}, - ), - (pd.period_range("1/1/2011", freq="M", periods=3), None, pd.PeriodDtype("M"), {}), - ( - pd.arrays.IntervalArray([pd.Interval(0, 1), pd.Interval(1, 5)]), - None, - pd.IntervalDtype("int64", "right"), - {}, - ), -] + +@pytest.fixture( + params=[ + ( + # data + [1, 2, 3], + # original dtype + np.dtype("int32"), + # default expected dtype + "Int32", + # exceptions on expected dtype + {("convert_integer", False): np.dtype("int32")}, + ), + ( + [1, 2, 3], + np.dtype("int64"), + "Int64", + {("convert_integer", False): np.dtype("int64")}, + ), + ( + ["x", "y", "z"], + np.dtype("O"), + pd.StringDtype(), + {("convert_string", False): np.dtype("O")}, + ), + ( + [True, False, np.nan], + np.dtype("O"), + pd.BooleanDtype(), + {("convert_boolean", False): np.dtype("O")}, + ), + ( + ["h", "i", np.nan], + np.dtype("O"), + pd.StringDtype(), + {("convert_string", False): np.dtype("O")}, + ), + ( # GH32117 + ["h", "i", 1], + np.dtype("O"), + np.dtype("O"), + {}, + ), + ( + [10, np.nan, 20], + np.dtype("float"), + "Int64", + { + ("convert_integer", False, "convert_floating", True): "Float64", + ("convert_integer", False, "convert_floating", False): np.dtype( + "float" + ), + }, + ), + ( + [np.nan, 100.5, 200], + np.dtype("float"), + "Float64", + {("convert_floating", False): np.dtype("float")}, + ), + ( + [3, 4, 5], + "Int8", + "Int8", + {}, + ), + ( + [[1, 2], [3, 4], [5]], + None, + np.dtype("O"), + {}, + ), + ( + [4, 5, 6], + np.dtype("uint32"), + "UInt32", + {("convert_integer", False): np.dtype("uint32")}, + ), + ( + [-10, 12, 13], + np.dtype("i1"), + "Int8", + {("convert_integer", False): np.dtype("i1")}, + ), + ( + [1.2, 1.3], + np.dtype("float32"), + "Float32", + {("convert_floating", False): np.dtype("float32")}, + ), + ( + [1, 2.0], + object, + "Int64", + { + ("convert_integer", False): "Float64", + ("convert_integer", False, "convert_floating", False): np.dtype( + "float" + ), + ("infer_objects", False): np.dtype("object"), + }, + ), + ( + [1, 2.5], + object, + "Float64", + { + ("convert_floating", False): np.dtype("float"), + ("infer_objects", False): np.dtype("object"), + }, + ), + (["a", "b"], pd.CategoricalDtype(), pd.CategoricalDtype(), {}), + ( + pd.to_datetime(["2020-01-14 10:00", "2020-01-15 11:11"]), + pd.DatetimeTZDtype(tz="UTC"), + pd.DatetimeTZDtype(tz="UTC"), + {}, + ), + ( + pd.to_datetime(["2020-01-14 10:00", "2020-01-15 11:11"]), + "datetime64[ns]", + np.dtype("datetime64[ns]"), + {}, + ), + ( + pd.to_datetime(["2020-01-14 10:00", "2020-01-15 11:11"]), + object, + np.dtype("datetime64[ns]"), + {("infer_objects", False): np.dtype("object")}, + ), + ( + pd.period_range("1/1/2011", freq="M", periods=3), + None, + pd.PeriodDtype("M"), + {}, + ), + ( + pd.arrays.IntervalArray([pd.Interval(0, 1), pd.Interval(1, 5)]), + None, + pd.IntervalDtype("int64", "right"), + {}, + ), + ] +) +def test_cases(request): + return request.param class TestSeriesConvertDtypes: - @pytest.mark.parametrize( - "data, maindtype, expected_default, expected_other", - test_cases, - ) @pytest.mark.parametrize("params", product(*[(True, False)] * 5)) def test_convert_dtypes( - self, data, maindtype, params, expected_default, expected_other + self, + test_cases, + params, ): + data, maindtype, expected_default, expected_other = test_cases if ( hasattr(data, "dtype") and data.dtype == "M8[ns]" diff --git a/pandas/tests/series/test_ufunc.py b/pandas/tests/series/test_ufunc.py index ac36103edcdcc..38dea7dc5f8bf 100644 --- a/pandas/tests/series/test_ufunc.py +++ b/pandas/tests/series/test_ufunc.py @@ -11,9 +11,16 @@ import pandas._testing as tm from pandas.arrays import SparseArray -BINARY_UFUNCS = [np.add, np.logaddexp] # dunder op -SPARSE = [True, False] -SPARSE_IDS = ["sparse", "dense"] + +@pytest.fixture(params=[np.add, np.logaddexp]) +def ufunc(request): + # dunder op + return request.param + + +@pytest.fixture(params=[True, False], ids=["sparse", "dense"]) +def sparse(request): + return request.param @pytest.fixture @@ -29,7 +36,6 @@ def arrays_for_binary_ufunc(): @pytest.mark.parametrize("ufunc", [np.positive, np.floor, np.exp]) -@pytest.mark.parametrize("sparse", SPARSE, ids=SPARSE_IDS) def test_unary_ufunc(ufunc, sparse): # Test that ufunc(pd.Series) == pd.Series(ufunc) arr = np.random.randint(0, 10, 10, dtype="int64") @@ -46,8 +52,6 @@ def test_unary_ufunc(ufunc, sparse): tm.assert_series_equal(result, expected) -@pytest.mark.parametrize("ufunc", BINARY_UFUNCS) -@pytest.mark.parametrize("sparse", SPARSE, ids=SPARSE_IDS) @pytest.mark.parametrize("flip", [True, False], ids=["flipped", "straight"]) def test_binary_ufunc_with_array(flip, sparse, ufunc, arrays_for_binary_ufunc): # Test that ufunc(pd.Series(a), array) == pd.Series(ufunc(a, b)) @@ -72,8 +76,6 @@ def test_binary_ufunc_with_array(flip, sparse, ufunc, arrays_for_binary_ufunc): tm.assert_series_equal(result, expected) -@pytest.mark.parametrize("ufunc", BINARY_UFUNCS) -@pytest.mark.parametrize("sparse", SPARSE, ids=SPARSE_IDS) @pytest.mark.parametrize("flip", [True, False], ids=["flipped", "straight"]) def test_binary_ufunc_with_index(flip, sparse, ufunc, arrays_for_binary_ufunc): # Test that @@ -101,8 +103,6 @@ def test_binary_ufunc_with_index(flip, sparse, ufunc, arrays_for_binary_ufunc): tm.assert_series_equal(result, expected) -@pytest.mark.parametrize("ufunc", BINARY_UFUNCS) -@pytest.mark.parametrize("sparse", SPARSE, ids=SPARSE_IDS) @pytest.mark.parametrize("shuffle", [True, False], ids=["unaligned", "aligned"]) @pytest.mark.parametrize("flip", [True, False], ids=["flipped", "straight"]) def test_binary_ufunc_with_series( @@ -143,8 +143,6 @@ def test_binary_ufunc_with_series( tm.assert_series_equal(result, expected) -@pytest.mark.parametrize("ufunc", BINARY_UFUNCS) -@pytest.mark.parametrize("sparse", SPARSE, ids=SPARSE_IDS) @pytest.mark.parametrize("flip", [True, False]) def test_binary_ufunc_scalar(ufunc, sparse, flip, arrays_for_binary_ufunc): # Test that @@ -170,7 +168,6 @@ def test_binary_ufunc_scalar(ufunc, sparse, flip, arrays_for_binary_ufunc): @pytest.mark.parametrize("ufunc", [np.divmod]) # TODO: np.modf, np.frexp -@pytest.mark.parametrize("sparse", SPARSE, ids=SPARSE_IDS) @pytest.mark.parametrize("shuffle", [True, False]) @pytest.mark.filterwarnings("ignore:divide by zero:RuntimeWarning") def test_multiple_output_binary_ufuncs(ufunc, sparse, shuffle, arrays_for_binary_ufunc): @@ -203,7 +200,6 @@ def test_multiple_output_binary_ufuncs(ufunc, sparse, shuffle, arrays_for_binary tm.assert_series_equal(result[1], pd.Series(expected[1])) -@pytest.mark.parametrize("sparse", SPARSE, ids=SPARSE_IDS) def test_multiple_output_ufunc(sparse, arrays_for_binary_ufunc): # Test that the same conditions from unary input apply to multi-output # ufuncs @@ -223,8 +219,6 @@ def test_multiple_output_ufunc(sparse, arrays_for_binary_ufunc): tm.assert_series_equal(result[1], pd.Series(expected[1], name="name")) -@pytest.mark.parametrize("sparse", SPARSE, ids=SPARSE_IDS) -@pytest.mark.parametrize("ufunc", BINARY_UFUNCS) def test_binary_ufunc_drops_series_name(ufunc, sparse, arrays_for_binary_ufunc): # Drop the names when they differ. a1, a2 = arrays_for_binary_ufunc diff --git a/pandas/tests/test_take.py b/pandas/tests/test_take.py index cefcf09613de1..47615be32e5b0 100644 --- a/pandas/tests/test_take.py +++ b/pandas/tests/test_take.py @@ -1,5 +1,4 @@ from datetime import datetime -import re import numpy as np import pytest @@ -41,9 +40,6 @@ def dtype_fill_out_dtype(request): class TestTake: - # Standard incompatible fill error. - fill_error = re.compile("Incompatible type for fill_value") - def test_1d_fill_nonna(self, dtype_fill_out_dtype): dtype, fill_value, out_dtype = dtype_fill_out_dtype data = np.random.randint(0, 2, 4).astype(dtype) diff --git a/pandas/tests/tseries/offsets/test_custom_business_month.py b/pandas/tests/tseries/offsets/test_custom_business_month.py index faf0f9810200b..0fff99ff8c025 100644 --- a/pandas/tests/tseries/offsets/test_custom_business_month.py +++ b/pandas/tests/tseries/offsets/test_custom_business_month.py @@ -11,7 +11,6 @@ datetime, timedelta, ) -from typing import TYPE_CHECKING import numpy as np import pytest @@ -34,9 +33,6 @@ from pandas.tseries import offsets from pandas.tseries.holiday import USFederalHolidayCalendar -if TYPE_CHECKING: - from pandas.tests.tseries.offsets.test_offsets import _ApplyCases - @pytest.fixture def dt(): @@ -132,7 +128,7 @@ def test_is_on_offset(self, case): offset, dt, expected = case assert_is_on_offset(offset, dt, expected) - apply_cases: _ApplyCases = [ + apply_cases = [ ( CBMonthBegin(), { @@ -330,7 +326,7 @@ def test_is_on_offset(self, case): offset, dt, expected = case assert_is_on_offset(offset, dt, expected) - apply_cases: _ApplyCases = [ + apply_cases = [ ( CBMonthEnd(), { diff --git a/pandas/tests/tseries/offsets/test_offsets.py b/pandas/tests/tseries/offsets/test_offsets.py index bfc5139c78b91..6df47968bd3bb 100644 --- a/pandas/tests/tseries/offsets/test_offsets.py +++ b/pandas/tests/tseries/offsets/test_offsets.py @@ -7,11 +7,6 @@ datetime, timedelta, ) -from typing import ( - Dict, - List, - Tuple, -) import numpy as np import pytest @@ -42,7 +37,6 @@ from pandas.tseries import offsets from pandas.tseries.offsets import ( FY5253, - BaseOffset, BDay, BMonthEnd, BusinessHour, @@ -61,8 +55,6 @@ WeekOfMonth, ) -_ApplyCases = List[Tuple[BaseOffset, Dict[datetime, datetime]]] - _ARITHMETIC_DATE_OFFSET = [ "years", "months", diff --git a/pandas/tests/util/test_validate_args.py b/pandas/tests/util/test_validate_args.py index 77e6b01ba1180..eef0931ec28ef 100644 --- a/pandas/tests/util/test_validate_args.py +++ b/pandas/tests/util/test_validate_args.py @@ -2,17 +2,20 @@ from pandas.util._validators import validate_args -_fname = "func" +@pytest.fixture +def _fname(): + return "func" -def test_bad_min_fname_arg_count(): + +def test_bad_min_fname_arg_count(_fname): msg = "'max_fname_arg_count' must be non-negative" with pytest.raises(ValueError, match=msg): validate_args(_fname, (None,), -1, "foo") -def test_bad_arg_length_max_value_single(): +def test_bad_arg_length_max_value_single(_fname): args = (None, None) compat_args = ("foo",) @@ -28,7 +31,7 @@ def test_bad_arg_length_max_value_single(): validate_args(_fname, args, min_fname_arg_count, compat_args) -def test_bad_arg_length_max_value_multiple(): +def test_bad_arg_length_max_value_multiple(_fname): args = (None, None) compat_args = {"foo": None} @@ -45,7 +48,7 @@ def test_bad_arg_length_max_value_multiple(): @pytest.mark.parametrize("i", range(1, 3)) -def test_not_all_defaults(i): +def test_not_all_defaults(i, _fname): bad_arg = "foo" msg = ( f"the '{bad_arg}' parameter is not supported " @@ -59,7 +62,7 @@ def test_not_all_defaults(i): validate_args(_fname, arg_vals[:i], 2, compat_args) -def test_validation(): +def test_validation(_fname): # No exceptions should be raised. validate_args(_fname, (None,), 2, {"out": None}) diff --git a/pandas/tests/util/test_validate_args_and_kwargs.py b/pandas/tests/util/test_validate_args_and_kwargs.py index 54d94d2194909..215026d648471 100644 --- a/pandas/tests/util/test_validate_args_and_kwargs.py +++ b/pandas/tests/util/test_validate_args_and_kwargs.py @@ -2,10 +2,13 @@ from pandas.util._validators import validate_args_and_kwargs -_fname = "func" +@pytest.fixture +def _fname(): + return "func" -def test_invalid_total_length_max_length_one(): + +def test_invalid_total_length_max_length_one(_fname): compat_args = ("foo",) kwargs = {"foo": "FOO"} args = ("FoO", "BaZ") @@ -23,7 +26,7 @@ def test_invalid_total_length_max_length_one(): validate_args_and_kwargs(_fname, args, kwargs, min_fname_arg_count, compat_args) -def test_invalid_total_length_max_length_multiple(): +def test_invalid_total_length_max_length_multiple(_fname): compat_args = ("foo", "bar", "baz") kwargs = {"foo": "FOO", "bar": "BAR"} args = ("FoO", "BaZ") @@ -42,7 +45,7 @@ def test_invalid_total_length_max_length_multiple(): @pytest.mark.parametrize("args,kwargs", [((), {"foo": -5, "bar": 2}), ((-5, 2), {})]) -def test_missing_args_or_kwargs(args, kwargs): +def test_missing_args_or_kwargs(args, kwargs, _fname): bad_arg = "bar" min_fname_arg_count = 2 @@ -57,7 +60,7 @@ def test_missing_args_or_kwargs(args, kwargs): validate_args_and_kwargs(_fname, args, kwargs, min_fname_arg_count, compat_args) -def test_duplicate_argument(): +def test_duplicate_argument(_fname): min_fname_arg_count = 2 compat_args = {"foo": None, "bar": None, "baz": None} @@ -70,7 +73,7 @@ def test_duplicate_argument(): validate_args_and_kwargs(_fname, args, kwargs, min_fname_arg_count, compat_args) -def test_validation(): +def test_validation(_fname): # No exceptions should be raised. compat_args = {"foo": 1, "bar": None, "baz": -2} kwargs = {"baz": -2} diff --git a/pandas/tests/util/test_validate_kwargs.py b/pandas/tests/util/test_validate_kwargs.py index de49cdd5e247d..dba447e30cf57 100644 --- a/pandas/tests/util/test_validate_kwargs.py +++ b/pandas/tests/util/test_validate_kwargs.py @@ -5,10 +5,13 @@ validate_kwargs, ) -_fname = "func" +@pytest.fixture +def _fname(): + return "func" -def test_bad_kwarg(): + +def test_bad_kwarg(_fname): good_arg = "f" bad_arg = good_arg + "o" @@ -22,7 +25,7 @@ def test_bad_kwarg(): @pytest.mark.parametrize("i", range(1, 3)) -def test_not_all_none(i): +def test_not_all_none(i, _fname): bad_arg = "foo" msg = ( rf"the '{bad_arg}' parameter is not supported " @@ -40,7 +43,7 @@ def test_not_all_none(i): validate_kwargs(_fname, kwargs, compat_args) -def test_validation(): +def test_validation(_fname): # No exceptions should be raised. compat_args = {"f": None, "b": 1, "ba": "s"}