diff --git a/pandas/tests/arithmetic/test_numeric.py b/pandas/tests/arithmetic/test_numeric.py index 121bfb78fe5c8..1b8ad1922b9d2 100644 --- a/pandas/tests/arithmetic/test_numeric.py +++ b/pandas/tests/arithmetic/test_numeric.py @@ -1116,11 +1116,10 @@ def test_ufunc_compat(self, holder, dtype): tm.assert_equal(result, expected) # TODO: add more dtypes - @pytest.mark.parametrize("holder", [Index, Series]) @pytest.mark.parametrize("dtype", [np.int64, np.uint64, np.float64]) - def test_ufunc_coercions(self, holder, dtype): - idx = holder([1, 2, 3, 4, 5], dtype=dtype, name="x") - box = Series if holder is Series else Index + def test_ufunc_coercions(self, index_or_series, dtype): + idx = index_or_series([1, 2, 3, 4, 5], dtype=dtype, name="x") + box = index_or_series result = np.sqrt(idx) assert result.dtype == "f8" and isinstance(result, box) diff --git a/pandas/tests/copy_view/test_constructors.py b/pandas/tests/copy_view/test_constructors.py index c325e49e8156e..cbd0e6899bfc9 100644 --- a/pandas/tests/copy_view/test_constructors.py +++ b/pandas/tests/copy_view/test_constructors.py @@ -283,14 +283,13 @@ def test_dataframe_from_dict_of_series_with_reindex(dtype): assert np.shares_memory(arr_before, arr_after) -@pytest.mark.parametrize("cons", [Series, Index]) @pytest.mark.parametrize( "data, dtype", [([1, 2], None), ([1, 2], "int64"), (["a", "b"], None)] ) def test_dataframe_from_series_or_index( - using_copy_on_write, warn_copy_on_write, data, dtype, cons + using_copy_on_write, warn_copy_on_write, data, dtype, index_or_series ): - obj = cons(data, dtype=dtype) + obj = index_or_series(data, dtype=dtype) obj_orig = obj.copy() df = DataFrame(obj, dtype=dtype) assert np.shares_memory(get_array(obj), get_array(df, 0)) @@ -303,9 +302,10 @@ def test_dataframe_from_series_or_index( tm.assert_equal(obj, obj_orig) -@pytest.mark.parametrize("cons", [Series, Index]) -def test_dataframe_from_series_or_index_different_dtype(using_copy_on_write, cons): - obj = cons([1, 2], dtype="int64") +def test_dataframe_from_series_or_index_different_dtype( + using_copy_on_write, index_or_series +): + obj = index_or_series([1, 2], dtype="int64") df = DataFrame(obj, dtype="int32") assert not np.shares_memory(get_array(obj), get_array(df, 0)) if using_copy_on_write: diff --git a/pandas/tests/dtypes/test_inference.py b/pandas/tests/dtypes/test_inference.py index e2ef83c243957..475473218f712 100644 --- a/pandas/tests/dtypes/test_inference.py +++ b/pandas/tests/dtypes/test_inference.py @@ -1701,19 +1701,19 @@ def test_interval_mismatched_subtype(self): arr = np.array([first, flt_interval], dtype=object) assert lib.infer_dtype(arr, skipna=False) == "interval" - @pytest.mark.parametrize("klass", [pd.array, Series]) @pytest.mark.parametrize("data", [["a", "b", "c"], ["a", "b", pd.NA]]) - def test_string_dtype(self, data, skipna, klass, nullable_string_dtype): + def test_string_dtype( + self, data, skipna, index_or_series_or_array, nullable_string_dtype + ): # StringArray - val = klass(data, dtype=nullable_string_dtype) + val = index_or_series_or_array(data, dtype=nullable_string_dtype) inferred = lib.infer_dtype(val, skipna=skipna) assert inferred == "string" - @pytest.mark.parametrize("klass", [pd.array, Series]) @pytest.mark.parametrize("data", [[True, False, True], [True, False, pd.NA]]) - def test_boolean_dtype(self, data, skipna, klass): + def test_boolean_dtype(self, data, skipna, index_or_series_or_array): # BooleanArray - val = klass(data, dtype="boolean") + val = index_or_series_or_array(data, dtype="boolean") inferred = lib.infer_dtype(val, skipna=skipna) assert inferred == "boolean" diff --git a/pandas/tests/extension/decimal/test_decimal.py b/pandas/tests/extension/decimal/test_decimal.py index 49f29b2194cae..a46663ef606f9 100644 --- a/pandas/tests/extension/decimal/test_decimal.py +++ b/pandas/tests/extension/decimal/test_decimal.py @@ -302,8 +302,7 @@ def test_dataframe_constructor_with_dtype(): tm.assert_frame_equal(result, expected) -@pytest.mark.parametrize("frame", [True, False]) -def test_astype_dispatches(frame): +def test_astype_dispatches(frame_or_series): # This is a dtype-specific test that ensures Series[decimal].astype # gets all the way through to ExtensionArray.astype # Designing a reliable smoke test that works for arbitrary data types @@ -312,12 +311,11 @@ def test_astype_dispatches(frame): ctx = decimal.Context() ctx.prec = 5 - if frame: - data = data.to_frame() + data = frame_or_series(data) result = data.astype(DecimalDtype(ctx)) - if frame: + if frame_or_series is pd.DataFrame: result = result["a"] assert result.dtype.context.prec == ctx.prec diff --git a/pandas/tests/frame/methods/test_set_index.py b/pandas/tests/frame/methods/test_set_index.py index 5724f79b82578..024af66ec0844 100644 --- a/pandas/tests/frame/methods/test_set_index.py +++ b/pandas/tests/frame/methods/test_set_index.py @@ -577,8 +577,8 @@ def test_set_index_raise_keys(self, frame_of_index_cols, drop, append): @pytest.mark.parametrize("append", [True, False]) @pytest.mark.parametrize("drop", [True, False]) - @pytest.mark.parametrize("box", [set], ids=["set"]) - def test_set_index_raise_on_type(self, frame_of_index_cols, box, drop, append): + def test_set_index_raise_on_type(self, frame_of_index_cols, drop, append): + box = set df = frame_of_index_cols msg = 'The parameter "keys" may be a column key, .*' diff --git a/pandas/tests/groupby/aggregate/test_numba.py b/pandas/tests/groupby/aggregate/test_numba.py index 89404a9bd09a3..964a80f8f3310 100644 --- a/pandas/tests/groupby/aggregate/test_numba.py +++ b/pandas/tests/groupby/aggregate/test_numba.py @@ -52,8 +52,7 @@ def incorrect_function(values, index): @pytest.mark.filterwarnings("ignore") # Filter warnings when parallel=True and the function can't be parallelized by Numba @pytest.mark.parametrize("jit", [True, False]) -@pytest.mark.parametrize("pandas_obj", ["Series", "DataFrame"]) -def test_numba_vs_cython(jit, pandas_obj, nogil, parallel, nopython, as_index): +def test_numba_vs_cython(jit, frame_or_series, nogil, parallel, nopython, as_index): pytest.importorskip("numba") def func_numba(values, index): @@ -70,7 +69,7 @@ def func_numba(values, index): ) engine_kwargs = {"nogil": nogil, "parallel": parallel, "nopython": nopython} grouped = data.groupby(0, as_index=as_index) - if pandas_obj == "Series": + if frame_or_series is Series: grouped = grouped[1] result = grouped.agg(func_numba, engine="numba", engine_kwargs=engine_kwargs) @@ -82,8 +81,7 @@ def func_numba(values, index): @pytest.mark.filterwarnings("ignore") # Filter warnings when parallel=True and the function can't be parallelized by Numba @pytest.mark.parametrize("jit", [True, False]) -@pytest.mark.parametrize("pandas_obj", ["Series", "DataFrame"]) -def test_cache(jit, pandas_obj, nogil, parallel, nopython): +def test_cache(jit, frame_or_series, nogil, parallel, nopython): # Test that the functions are cached correctly if we switch functions pytest.importorskip("numba") @@ -104,7 +102,7 @@ def func_2(values, index): ) engine_kwargs = {"nogil": nogil, "parallel": parallel, "nopython": nopython} grouped = data.groupby(0) - if pandas_obj == "Series": + if frame_or_series is Series: grouped = grouped[1] result = grouped.agg(func_1, engine="numba", engine_kwargs=engine_kwargs) diff --git a/pandas/tests/groupby/transform/test_numba.py b/pandas/tests/groupby/transform/test_numba.py index af11dae0aabfe..b75113d3f4e14 100644 --- a/pandas/tests/groupby/transform/test_numba.py +++ b/pandas/tests/groupby/transform/test_numba.py @@ -50,8 +50,7 @@ def incorrect_function(values, index): @pytest.mark.filterwarnings("ignore") # Filter warnings when parallel=True and the function can't be parallelized by Numba @pytest.mark.parametrize("jit", [True, False]) -@pytest.mark.parametrize("pandas_obj", ["Series", "DataFrame"]) -def test_numba_vs_cython(jit, pandas_obj, nogil, parallel, nopython, as_index): +def test_numba_vs_cython(jit, frame_or_series, nogil, parallel, nopython, as_index): pytest.importorskip("numba") def func(values, index): @@ -68,7 +67,7 @@ def func(values, index): ) engine_kwargs = {"nogil": nogil, "parallel": parallel, "nopython": nopython} grouped = data.groupby(0, as_index=as_index) - if pandas_obj == "Series": + if frame_or_series is Series: grouped = grouped[1] result = grouped.transform(func, engine="numba", engine_kwargs=engine_kwargs) @@ -80,8 +79,7 @@ def func(values, index): @pytest.mark.filterwarnings("ignore") # Filter warnings when parallel=True and the function can't be parallelized by Numba @pytest.mark.parametrize("jit", [True, False]) -@pytest.mark.parametrize("pandas_obj", ["Series", "DataFrame"]) -def test_cache(jit, pandas_obj, nogil, parallel, nopython): +def test_cache(jit, frame_or_series, nogil, parallel, nopython): # Test that the functions are cached correctly if we switch functions pytest.importorskip("numba") @@ -102,7 +100,7 @@ def func_2(values, index): ) engine_kwargs = {"nogil": nogil, "parallel": parallel, "nopython": nopython} grouped = data.groupby(0) - if pandas_obj == "Series": + if frame_or_series is Series: grouped = grouped[1] result = grouped.transform(func_1, engine="numba", engine_kwargs=engine_kwargs) diff --git a/pandas/tests/indexing/test_iloc.py b/pandas/tests/indexing/test_iloc.py index e0898a636474c..f36ddff223a9a 100644 --- a/pandas/tests/indexing/test_iloc.py +++ b/pandas/tests/indexing/test_iloc.py @@ -106,8 +106,9 @@ def test_iloc_setitem_fullcol_categorical(self, indexer, key): expected = DataFrame({0: Series(cat.astype(object), dtype=object), 1: range(3)}) tm.assert_frame_equal(df, expected) - @pytest.mark.parametrize("box", [array, Series]) - def test_iloc_setitem_ea_inplace(self, frame_or_series, box, using_copy_on_write): + def test_iloc_setitem_ea_inplace( + self, frame_or_series, index_or_series_or_array, using_copy_on_write + ): # GH#38952 Case with not setting a full column # IntegerArray without NAs arr = array([1, 2, 3, 4]) @@ -119,9 +120,9 @@ def test_iloc_setitem_ea_inplace(self, frame_or_series, box, using_copy_on_write values = obj._mgr.arrays[0] if frame_or_series is Series: - obj.iloc[:2] = box(arr[2:]) + obj.iloc[:2] = index_or_series_or_array(arr[2:]) else: - obj.iloc[:2, 0] = box(arr[2:]) + obj.iloc[:2, 0] = index_or_series_or_array(arr[2:]) expected = frame_or_series(np.array([3, 4, 3, 4], dtype="i8")) tm.assert_equal(obj, expected) diff --git a/pandas/tests/reductions/test_stat_reductions.py b/pandas/tests/reductions/test_stat_reductions.py index 8fbb78737474c..a6aaeba1dc3a8 100644 --- a/pandas/tests/reductions/test_stat_reductions.py +++ b/pandas/tests/reductions/test_stat_reductions.py @@ -16,8 +16,7 @@ class TestDatetimeLikeStatReductions: - @pytest.mark.parametrize("box", [Series, pd.Index, pd.array]) - def test_dt64_mean(self, tz_naive_fixture, box): + def test_dt64_mean(self, tz_naive_fixture, index_or_series_or_array): tz = tz_naive_fixture dti = date_range("2001-01-01", periods=11, tz=tz) @@ -25,20 +24,19 @@ def test_dt64_mean(self, tz_naive_fixture, box): dti = dti.take([4, 1, 3, 10, 9, 7, 8, 5, 0, 2, 6]) dtarr = dti._data - obj = box(dtarr) + obj = index_or_series_or_array(dtarr) assert obj.mean() == pd.Timestamp("2001-01-06", tz=tz) assert obj.mean(skipna=False) == pd.Timestamp("2001-01-06", tz=tz) # dtarr[-2] will be the first date 2001-01-1 dtarr[-2] = pd.NaT - obj = box(dtarr) + obj = index_or_series_or_array(dtarr) assert obj.mean() == pd.Timestamp("2001-01-06 07:12:00", tz=tz) assert obj.mean(skipna=False) is pd.NaT - @pytest.mark.parametrize("box", [Series, pd.Index, pd.array]) @pytest.mark.parametrize("freq", ["s", "h", "D", "W", "B"]) - def test_period_mean(self, box, freq): + def test_period_mean(self, index_or_series_or_array, freq): # GH#24757 dti = date_range("2001-01-01", periods=11) # shuffle so that we are not just working with monotone-increasing @@ -48,7 +46,7 @@ def test_period_mean(self, box, freq): msg = r"PeriodDtype\[B\] is deprecated" with tm.assert_produces_warning(warn, match=msg): parr = dti._data.to_period(freq) - obj = box(parr) + obj = index_or_series_or_array(parr) with pytest.raises(TypeError, match="ambiguous"): obj.mean() with pytest.raises(TypeError, match="ambiguous"): @@ -62,13 +60,12 @@ def test_period_mean(self, box, freq): with pytest.raises(TypeError, match="ambiguous"): obj.mean(skipna=True) - @pytest.mark.parametrize("box", [Series, pd.Index, pd.array]) - def test_td64_mean(self, box): + def test_td64_mean(self, index_or_series_or_array): m8values = np.array([0, 3, -2, -7, 1, 2, -1, 3, 5, -2, 4], "m8[D]") tdi = pd.TimedeltaIndex(m8values).as_unit("ns") tdarr = tdi._data - obj = box(tdarr, copy=False) + obj = index_or_series_or_array(tdarr, copy=False) result = obj.mean() expected = np.array(tdarr).mean() diff --git a/pandas/tests/resample/test_base.py b/pandas/tests/resample/test_base.py index f20518c7be98a..6ba2ac0104e75 100644 --- a/pandas/tests/resample/test_base.py +++ b/pandas/tests/resample/test_base.py @@ -30,9 +30,8 @@ date_range(datetime(2005, 1, 1), datetime(2005, 1, 10), freq="D"), ], ) -@pytest.mark.parametrize("klass", [DataFrame, Series]) -def test_asfreq(klass, index, freq): - obj = klass(range(len(index)), index=index) +def test_asfreq(frame_or_series, index, freq): + obj = frame_or_series(range(len(index)), index=index) idx_range = date_range if isinstance(index, DatetimeIndex) else timedelta_range result = obj.resample(freq).asfreq() diff --git a/pandas/tests/resample/test_period_index.py b/pandas/tests/resample/test_period_index.py index cf77238a553d0..3be11e0a5ad2f 100644 --- a/pandas/tests/resample/test_period_index.py +++ b/pandas/tests/resample/test_period_index.py @@ -59,12 +59,11 @@ def _simple_period_range_series(start, end, freq="D"): class TestPeriodIndex: @pytest.mark.parametrize("freq", ["2D", "1h", "2h"]) @pytest.mark.parametrize("kind", ["period", None, "timestamp"]) - @pytest.mark.parametrize("klass", [DataFrame, Series]) - def test_asfreq(self, klass, freq, kind): + def test_asfreq(self, frame_or_series, freq, kind): # GH 12884, 15944 # make sure .asfreq() returns PeriodIndex (except kind='timestamp') - obj = klass(range(5), index=period_range("2020-01-01", periods=5)) + obj = frame_or_series(range(5), index=period_range("2020-01-01", periods=5)) if kind == "timestamp": expected = obj.to_timestamp().resample(freq).asfreq() else: @@ -1007,12 +1006,11 @@ def test_resample_t_l_deprecated(self): offsets.BusinessHour(2), ], ) - @pytest.mark.parametrize("klass", [DataFrame, Series]) - def test_asfreq_invalid_period_freq(self, offset, klass): + def test_asfreq_invalid_period_freq(self, offset, frame_or_series): # GH#9586 msg = f"Invalid offset: '{offset.base}' for converting time series " - obj = klass(range(5), index=period_range("2020-01-01", periods=5)) + obj = frame_or_series(range(5), index=period_range("2020-01-01", periods=5)) with pytest.raises(ValueError, match=msg): obj.asfreq(freq=offset) @@ -1027,12 +1025,11 @@ def test_asfreq_invalid_period_freq(self, offset, klass): ("2Y-MAR", "2YE-MAR"), ], ) -@pytest.mark.parametrize("klass", [DataFrame, Series]) -def test_resample_frequency_ME_QE_YE_error_message(klass, freq, freq_depr): +def test_resample_frequency_ME_QE_YE_error_message(frame_or_series, freq, freq_depr): # GH#9586 msg = f"for Period, please use '{freq[1:]}' instead of '{freq_depr[1:]}'" - obj = klass(range(5), index=period_range("2020-01-01", periods=5)) + obj = frame_or_series(range(5), index=period_range("2020-01-01", periods=5)) with pytest.raises(ValueError, match=msg): obj.resample(freq_depr) @@ -1057,11 +1054,10 @@ def test_corner_cases_period(simple_period_range_series): "2BYE-MAR", ], ) -@pytest.mark.parametrize("klass", [DataFrame, Series]) -def test_resample_frequency_invalid_freq(klass, freq_depr): +def test_resample_frequency_invalid_freq(frame_or_series, freq_depr): # GH#9586 msg = f"Invalid frequency: {freq_depr[1:]}" - obj = klass(range(5), index=period_range("2020-01-01", periods=5)) + obj = frame_or_series(range(5), index=period_range("2020-01-01", periods=5)) with pytest.raises(ValueError, match=msg): obj.resample(freq_depr) diff --git a/pandas/tests/reshape/concat/test_concat.py b/pandas/tests/reshape/concat/test_concat.py index 5ec95cbf24b39..d8bc7974b4139 100644 --- a/pandas/tests/reshape/concat/test_concat.py +++ b/pandas/tests/reshape/concat/test_concat.py @@ -545,14 +545,13 @@ def test_concat_no_unnecessary_upcast(float_numpy_dtype, frame_or_series): assert x.values.dtype == dt -@pytest.mark.parametrize("pdt", [Series, DataFrame]) -def test_concat_will_upcast(pdt, any_signed_int_numpy_dtype): +def test_concat_will_upcast(frame_or_series, any_signed_int_numpy_dtype): dt = any_signed_int_numpy_dtype - dims = pdt().ndim + dims = frame_or_series().ndim dfs = [ - pdt(np.array([1], dtype=dt, ndmin=dims)), - pdt(np.array([np.nan], ndmin=dims)), - pdt(np.array([5], dtype=dt, ndmin=dims)), + frame_or_series(np.array([1], dtype=dt, ndmin=dims)), + frame_or_series(np.array([np.nan], ndmin=dims)), + frame_or_series(np.array([5], dtype=dt, ndmin=dims)), ] x = concat(dfs) assert x.values.dtype == "float64" diff --git a/pandas/tests/series/methods/test_view.py b/pandas/tests/series/methods/test_view.py index 7e0ac372cd443..9d1478cd9f689 100644 --- a/pandas/tests/series/methods/test_view.py +++ b/pandas/tests/series/methods/test_view.py @@ -2,9 +2,7 @@ import pytest from pandas import ( - Index, Series, - array, date_range, ) import pandas._testing as tm @@ -47,11 +45,10 @@ def test_view_tz(self): @pytest.mark.parametrize( "second", ["m8[ns]", "M8[ns]", "M8[ns, US/Central]", "period[D]"] ) - @pytest.mark.parametrize("box", [Series, Index, array]) - def test_view_between_datetimelike(self, first, second, box): + def test_view_between_datetimelike(self, first, second, index_or_series_or_array): dti = date_range("2016-01-01", periods=3) - orig = box(dti) + orig = index_or_series_or_array(dti) obj = orig.view(first) assert obj.dtype == first tm.assert_numpy_array_equal(np.asarray(obj.view("i8")), dti.asi8) diff --git a/pandas/tests/test_expressions.py b/pandas/tests/test_expressions.py index dfec99f0786eb..71994d186163e 100644 --- a/pandas/tests/test_expressions.py +++ b/pandas/tests/test_expressions.py @@ -6,11 +6,7 @@ from pandas import option_context import pandas._testing as tm -from pandas.core.api import ( - DataFrame, - Index, - Series, -) +from pandas.core.api import DataFrame from pandas.core.computation import expressions as expr @@ -433,16 +429,15 @@ def test_frame_series_axis(self, axis, arith, _frame, monkeypatch): "__rfloordiv__", ], ) - @pytest.mark.parametrize("box", [DataFrame, Series, Index]) @pytest.mark.parametrize("scalar", [-5, 5]) def test_python_semantics_with_numexpr_installed( - self, op, box, scalar, monkeypatch + self, op, box_with_array, scalar, monkeypatch ): # https://github.com/pandas-dev/pandas/issues/36047 with monkeypatch.context() as m: m.setattr(expr, "_MIN_ELEMENTS", 0) data = np.arange(-50, 50) - obj = box(data) + obj = box_with_array(data) method = getattr(obj, op) result = method(scalar) @@ -454,7 +449,7 @@ def test_python_semantics_with_numexpr_installed( # compare result element-wise with Python for i, elem in enumerate(data): - if box == DataFrame: + if box_with_array == DataFrame: scalar_result = result.iloc[i, 0] else: scalar_result = result[i] diff --git a/pandas/tests/tools/test_to_datetime.py b/pandas/tests/tools/test_to_datetime.py index cb94427ae8961..4a012f34ddc3b 100644 --- a/pandas/tests/tools/test_to_datetime.py +++ b/pandas/tests/tools/test_to_datetime.py @@ -988,14 +988,13 @@ def test_to_datetime_dtarr(self, tz): # Doesn't work on Windows since tzpath not set correctly @td.skip_if_windows - @pytest.mark.parametrize("arg_class", [Series, Index]) @pytest.mark.parametrize("utc", [True, False]) @pytest.mark.parametrize("tz", [None, "US/Central"]) - def test_to_datetime_arrow(self, tz, utc, arg_class): + def test_to_datetime_arrow(self, tz, utc, index_or_series): pa = pytest.importorskip("pyarrow") dti = date_range("1965-04-03", periods=19, freq="2W", tz=tz) - dti = arg_class(dti) + dti = index_or_series(dti) dti_arrow = dti.astype(pd.ArrowDtype(pa.timestamp(unit="ns", tz=tz))) @@ -1003,11 +1002,11 @@ def test_to_datetime_arrow(self, tz, utc, arg_class): expected = to_datetime(dti, utc=utc).astype( pd.ArrowDtype(pa.timestamp(unit="ns", tz=tz if not utc else "UTC")) ) - if not utc and arg_class is not Series: + if not utc and index_or_series is not Series: # Doesn't hold for utc=True, since that will astype # to_datetime also returns a new object for series assert result is dti_arrow - if arg_class is Series: + if index_or_series is Series: tm.assert_series_equal(result, expected) else: tm.assert_index_equal(result, expected) diff --git a/pandas/tests/util/test_assert_frame_equal.py b/pandas/tests/util/test_assert_frame_equal.py index 79132591b15b3..e244615ea4629 100644 --- a/pandas/tests/util/test_assert_frame_equal.py +++ b/pandas/tests/util/test_assert_frame_equal.py @@ -10,11 +10,6 @@ def by_blocks_fixture(request): return request.param -@pytest.fixture(params=["DataFrame", "Series"]) -def obj_fixture(request): - return request.param - - def _assert_frame_equal_both(a, b, **kwargs): """ Check that two DataFrame equal. @@ -35,16 +30,20 @@ def _assert_frame_equal_both(a, b, **kwargs): @pytest.mark.parametrize("check_like", [True, False]) -def test_frame_equal_row_order_mismatch(check_like, obj_fixture): +def test_frame_equal_row_order_mismatch(check_like, frame_or_series): df1 = DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]}, index=["a", "b", "c"]) df2 = DataFrame({"A": [3, 2, 1], "B": [6, 5, 4]}, index=["c", "b", "a"]) if not check_like: # Do not ignore row-column orderings. - msg = f"{obj_fixture}.index are different" + msg = f"{frame_or_series.__name__}.index are different" with pytest.raises(AssertionError, match=msg): - tm.assert_frame_equal(df1, df2, check_like=check_like, obj=obj_fixture) + tm.assert_frame_equal( + df1, df2, check_like=check_like, obj=frame_or_series.__name__ + ) else: - _assert_frame_equal_both(df1, df2, check_like=check_like, obj=obj_fixture) + _assert_frame_equal_both( + df1, df2, check_like=check_like, obj=frame_or_series.__name__ + ) @pytest.mark.parametrize( @@ -54,11 +53,11 @@ def test_frame_equal_row_order_mismatch(check_like, obj_fixture): (DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]}), DataFrame({"A": [1, 2, 3]})), ], ) -def test_frame_equal_shape_mismatch(df1, df2, obj_fixture): - msg = f"{obj_fixture} are different" +def test_frame_equal_shape_mismatch(df1, df2, frame_or_series): + msg = f"{frame_or_series.__name__} are different" with pytest.raises(AssertionError, match=msg): - tm.assert_frame_equal(df1, df2, obj=obj_fixture) + tm.assert_frame_equal(df1, df2, obj=frame_or_series.__name__) @pytest.mark.parametrize( @@ -109,14 +108,14 @@ def test_empty_dtypes(check_dtype): @pytest.mark.parametrize("check_like", [True, False]) -def test_frame_equal_index_mismatch(check_like, obj_fixture, using_infer_string): +def test_frame_equal_index_mismatch(check_like, frame_or_series, using_infer_string): if using_infer_string: dtype = "string" else: dtype = "object" - msg = f"""{obj_fixture}\\.index are different + msg = f"""{frame_or_series.__name__}\\.index are different -{obj_fixture}\\.index values are different \\(33\\.33333 %\\) +{frame_or_series.__name__}\\.index values are different \\(33\\.33333 %\\) \\[left\\]: Index\\(\\['a', 'b', 'c'\\], dtype='{dtype}'\\) \\[right\\]: Index\\(\\['a', 'b', 'd'\\], dtype='{dtype}'\\) At positional index 2, first diff: c != d""" @@ -125,18 +124,20 @@ def test_frame_equal_index_mismatch(check_like, obj_fixture, using_infer_string) df2 = DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]}, index=["a", "b", "d"]) with pytest.raises(AssertionError, match=msg): - tm.assert_frame_equal(df1, df2, check_like=check_like, obj=obj_fixture) + tm.assert_frame_equal( + df1, df2, check_like=check_like, obj=frame_or_series.__name__ + ) @pytest.mark.parametrize("check_like", [True, False]) -def test_frame_equal_columns_mismatch(check_like, obj_fixture, using_infer_string): +def test_frame_equal_columns_mismatch(check_like, frame_or_series, using_infer_string): if using_infer_string: dtype = "string" else: dtype = "object" - msg = f"""{obj_fixture}\\.columns are different + msg = f"""{frame_or_series.__name__}\\.columns are different -{obj_fixture}\\.columns values are different \\(50\\.0 %\\) +{frame_or_series.__name__}\\.columns values are different \\(50\\.0 %\\) \\[left\\]: Index\\(\\['A', 'B'\\], dtype='{dtype}'\\) \\[right\\]: Index\\(\\['A', 'b'\\], dtype='{dtype}'\\)""" @@ -144,11 +145,13 @@ def test_frame_equal_columns_mismatch(check_like, obj_fixture, using_infer_strin df2 = DataFrame({"A": [1, 2, 3], "b": [4, 5, 6]}, index=["a", "b", "c"]) with pytest.raises(AssertionError, match=msg): - tm.assert_frame_equal(df1, df2, check_like=check_like, obj=obj_fixture) + tm.assert_frame_equal( + df1, df2, check_like=check_like, obj=frame_or_series.__name__ + ) -def test_frame_equal_block_mismatch(by_blocks_fixture, obj_fixture): - obj = obj_fixture +def test_frame_equal_block_mismatch(by_blocks_fixture, frame_or_series): + obj = frame_or_series.__name__ msg = f"""{obj}\\.iloc\\[:, 1\\] \\(column name="B"\\) are different {obj}\\.iloc\\[:, 1\\] \\(column name="B"\\) values are different \\(33\\.33333 %\\) @@ -160,7 +163,7 @@ def test_frame_equal_block_mismatch(by_blocks_fixture, obj_fixture): df2 = DataFrame({"A": [1, 2, 3], "B": [4, 5, 7]}) with pytest.raises(AssertionError, match=msg): - tm.assert_frame_equal(df1, df2, by_blocks=by_blocks_fixture, obj=obj_fixture) + tm.assert_frame_equal(df1, df2, by_blocks=by_blocks_fixture, obj=obj) @pytest.mark.parametrize( @@ -188,14 +191,16 @@ def test_frame_equal_block_mismatch(by_blocks_fixture, obj_fixture): ), ], ) -def test_frame_equal_unicode(df1, df2, msg, by_blocks_fixture, obj_fixture): +def test_frame_equal_unicode(df1, df2, msg, by_blocks_fixture, frame_or_series): # see gh-20503 # # Test ensures that `tm.assert_frame_equals` raises the right exception # when comparing DataFrames containing differing unicode objects. - msg = msg.format(obj=obj_fixture) + msg = msg.format(obj=frame_or_series.__name__) with pytest.raises(AssertionError, match=msg): - tm.assert_frame_equal(df1, df2, by_blocks=by_blocks_fixture, obj=obj_fixture) + tm.assert_frame_equal( + df1, df2, by_blocks=by_blocks_fixture, obj=frame_or_series.__name__ + ) def test_assert_frame_equal_extension_dtype_mismatch():