From 18651becd6d99a1f8689e2fa500e382892b30c23 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Sat, 5 Feb 2022 16:15:43 -0800 Subject: [PATCH] TST: Remove unused fixtures in tests --- pandas/conftest.py | 2 +- pandas/tests/apply/test_str.py | 2 +- pandas/tests/frame/indexing/test_where.py | 2 +- pandas/tests/frame/methods/test_shift.py | 2 +- .../tests/indexes/period/test_constructors.py | 3 - pandas/tests/indexing/test_loc.py | 2 +- .../tests/io/json/test_json_table_schema.py | 78 ++++++++++--------- pandas/tests/io/parser/test_parse_dates.py | 2 - pandas/tests/io/pytables/test_round_trip.py | 16 +--- pandas/tests/io/pytables/test_select.py | 2 +- pandas/tests/io/test_fsspec.py | 2 +- pandas/tests/io/test_parquet.py | 4 +- 12 files changed, 51 insertions(+), 66 deletions(-) diff --git a/pandas/conftest.py b/pandas/conftest.py index a9c8ab833b40f..54f49bb9f7fd6 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -1776,7 +1776,7 @@ def indexer_ial(request): @pytest.fixture -def using_array_manager(request): +def using_array_manager(): """ Fixture to check if the array manager is being used. """ diff --git a/pandas/tests/apply/test_str.py b/pandas/tests/apply/test_str.py index 4fefc79e04aad..266423fea689d 100644 --- a/pandas/tests/apply/test_str.py +++ b/pandas/tests/apply/test_str.py @@ -256,7 +256,7 @@ def test_transform_groupby_kernel_series(string_series, op): @pytest.mark.parametrize("op", frame_transform_kernels) -def test_transform_groupby_kernel_frame(axis, float_frame, op, request): +def test_transform_groupby_kernel_frame(axis, float_frame, op): # TODO(2.0) Remove after pad/backfill deprecation enforced op = maybe_normalize_deprecated_kernels(op) # GH 35964 diff --git a/pandas/tests/frame/indexing/test_where.py b/pandas/tests/frame/indexing/test_where.py index d2fa187106e1b..328155ef57997 100644 --- a/pandas/tests/frame/indexing/test_where.py +++ b/pandas/tests/frame/indexing/test_where.py @@ -98,7 +98,7 @@ def test_where_upcasting(self): tm.assert_series_equal(result, expected) - def test_where_alignment(self, where_frame, float_string_frame, mixed_int_frame): + def test_where_alignment(self, where_frame, float_string_frame): # aligning def _check_align(df, cond, other, check_dtypes=True): rs = df.where(cond, other) diff --git a/pandas/tests/frame/methods/test_shift.py b/pandas/tests/frame/methods/test_shift.py index c053289bbe11a..9947e68bc6f46 100644 --- a/pandas/tests/frame/methods/test_shift.py +++ b/pandas/tests/frame/methods/test_shift.py @@ -611,7 +611,7 @@ def test_shift_dt64values_int_fill_deprecated(self): ) # TODO(2.0): remove filtering @pytest.mark.filterwarnings("ignore:Index.ravel.*:FutureWarning") - def test_shift_dt64values_axis1_invalid_fill(self, vals, as_cat, request): + def test_shift_dt64values_axis1_invalid_fill(self, vals, as_cat): # GH#44564 ser = Series(vals) if as_cat: diff --git a/pandas/tests/indexes/period/test_constructors.py b/pandas/tests/indexes/period/test_constructors.py index e372fd007630a..fdc286ef7ec1a 100644 --- a/pandas/tests/indexes/period/test_constructors.py +++ b/pandas/tests/indexes/period/test_constructors.py @@ -534,9 +534,6 @@ def test_shallow_copy_requires_disallow_period_index(self): class TestSeriesPeriod: - def setup_method(self, method): - self.series = Series(period_range("2000-01-01", periods=10, freq="D")) - def test_constructor_cant_cast_period(self): msg = "Cannot cast PeriodIndex to dtype float64" with pytest.raises(TypeError, match=msg): diff --git a/pandas/tests/indexing/test_loc.py b/pandas/tests/indexing/test_loc.py index 49aa4d3d0dbf0..d16d086a37d3d 100644 --- a/pandas/tests/indexing/test_loc.py +++ b/pandas/tests/indexing/test_loc.py @@ -1979,7 +1979,7 @@ def test_loc_setitem_with_expansion_inf_upcast_empty(self): tm.assert_index_equal(result, expected) @pytest.mark.filterwarnings("ignore:indexing past lexsort depth") - def test_loc_setitem_with_expansion_nonunique_index(self, index, request): + def test_loc_setitem_with_expansion_nonunique_index(self, index): # GH#40096 if not len(index): return diff --git a/pandas/tests/io/json/test_json_table_schema.py b/pandas/tests/io/json/test_json_table_schema.py index f7aade1f27529..a2fd8d2cbbf04 100644 --- a/pandas/tests/io/json/test_json_table_schema.py +++ b/pandas/tests/io/json/test_json_table_schema.py @@ -24,20 +24,39 @@ ) -class TestBuildSchema: - def setup_method(self, method): - self.df = DataFrame( - { - "A": [1, 2, 3, 4], - "B": ["a", "b", "c", "c"], - "C": pd.date_range("2016-01-01", freq="d", periods=4), - "D": pd.timedelta_range("1H", periods=4, freq="T"), - }, - index=pd.Index(range(4), name="idx"), - ) +@pytest.fixture +def df_schema(): + return DataFrame( + { + "A": [1, 2, 3, 4], + "B": ["a", "b", "c", "c"], + "C": pd.date_range("2016-01-01", freq="d", periods=4), + "D": pd.timedelta_range("1H", periods=4, freq="T"), + }, + index=pd.Index(range(4), name="idx"), + ) + + +@pytest.fixture +def df_table(): + return DataFrame( + { + "A": [1, 2, 3, 4], + "B": ["a", "b", "c", "c"], + "C": pd.date_range("2016-01-01", freq="d", periods=4), + "D": pd.timedelta_range("1H", periods=4, freq="T"), + "E": pd.Series(pd.Categorical(["a", "b", "c", "c"])), + "F": pd.Series(pd.Categorical(["a", "b", "c", "c"], ordered=True)), + "G": [1.0, 2.0, 3, 4.0], + "H": pd.date_range("2016-01-01", freq="d", periods=4, tz="US/Central"), + }, + index=pd.Index(range(4), name="idx"), + ) - def test_build_table_schema(self): - result = build_table_schema(self.df, version=False) + +class TestBuildSchema: + def test_build_table_schema(self, df_schema): + result = build_table_schema(df_schema, version=False) expected = { "fields": [ {"name": "idx", "type": "integer"}, @@ -49,7 +68,7 @@ def test_build_table_schema(self): "primaryKey": ["idx"], } assert result == expected - result = build_table_schema(self.df) + result = build_table_schema(df_schema) assert "pandas_version" in result def test_series(self): @@ -77,8 +96,8 @@ def test_series_unnamed(self): } assert result == expected - def test_multiindex(self): - df = self.df.copy() + def test_multiindex(self, df_schema): + df = df_schema idx = pd.MultiIndex.from_product([("a", "b"), (1, 2)]) df.index = idx @@ -195,21 +214,6 @@ def test_as_json_table_type_categorical_dtypes(self): class TestTableOrient: - def setup_method(self, method): - self.df = DataFrame( - { - "A": [1, 2, 3, 4], - "B": ["a", "b", "c", "c"], - "C": pd.date_range("2016-01-01", freq="d", periods=4), - "D": pd.timedelta_range("1H", periods=4, freq="T"), - "E": pd.Series(pd.Categorical(["a", "b", "c", "c"])), - "F": pd.Series(pd.Categorical(["a", "b", "c", "c"], ordered=True)), - "G": [1.0, 2.0, 3, 4.0], - "H": pd.date_range("2016-01-01", freq="d", periods=4, tz="US/Central"), - }, - index=pd.Index(range(4), name="idx"), - ) - def test_build_series(self): s = pd.Series([1, 2], name="a") s.index.name = "id" @@ -259,8 +263,8 @@ def test_read_json_from_to_json_results(self): @pytest.mark.filterwarnings( "ignore:an integer is required (got type float)*:DeprecationWarning" ) - def test_to_json(self): - df = self.df.copy() + def test_to_json(self, df_table): + df = df_table df.index.name = "idx" result = df.to_json(orient="table", date_format="iso") result = json.loads(result, object_pairs_hook=OrderedDict) @@ -438,17 +442,17 @@ def test_to_json_categorical_index(self): @pytest.mark.filterwarnings( "ignore:an integer is required (got type float)*:DeprecationWarning" ) - def test_date_format_raises(self): + def test_date_format_raises(self, df_table): msg = ( "Trying to write with `orient='table'` and `date_format='epoch'`. Table " "Schema requires dates to be formatted with `date_format='iso'`" ) with pytest.raises(ValueError, match=msg): - self.df.to_json(orient="table", date_format="epoch") + df_table.to_json(orient="table", date_format="epoch") # others work - self.df.to_json(orient="table", date_format="iso") - self.df.to_json(orient="table") + df_table.to_json(orient="table", date_format="iso") + df_table.to_json(orient="table") def test_convert_pandas_type_to_json_field_int(self, index_or_series): kind = index_or_series diff --git a/pandas/tests/io/parser/test_parse_dates.py b/pandas/tests/io/parser/test_parse_dates.py index 54e671bbb5baf..4fa40296fbe56 100644 --- a/pandas/tests/io/parser/test_parse_dates.py +++ b/pandas/tests/io/parser/test_parse_dates.py @@ -1713,8 +1713,6 @@ def test_hypothesis_delimited_date( "e.g. %m.%Y is a float or a date" ) ) - result, expected = None, None - except_in_dateutil, except_out_dateutil = None, None date_string = test_datetime.strftime(date_format.replace(" ", delimiter)) with warnings.catch_warnings(): diff --git a/pandas/tests/io/pytables/test_round_trip.py b/pandas/tests/io/pytables/test_round_trip.py index 867525a7146b4..9d360ef2a052c 100644 --- a/pandas/tests/io/pytables/test_round_trip.py +++ b/pandas/tests/io/pytables/test_round_trip.py @@ -33,7 +33,7 @@ pytestmark = pytest.mark.single -def test_conv_read_write(setup_path): +def test_conv_read_write(): with tm.ensure_clean() as path: def roundtrip(key, obj, **kwargs): @@ -491,20 +491,6 @@ def _check_roundtrip(obj, comparator, path, compression=False, **kwargs): comparator(retrieved, obj, **kwargs) -def _check_double_roundtrip(self, obj, comparator, path, compression=False, **kwargs): - options = {} - if compression: - options["complib"] = compression or _default_compressor - - with ensure_clean_store(path, "w", **options) as store: - store["obj"] = obj - retrieved = store["obj"] - comparator(retrieved, obj, **kwargs) - store["obj"] = retrieved - again = store["obj"] - comparator(again, obj, **kwargs) - - def _check_roundtrip_table(obj, comparator, path, compression=False): options = {} if compression: diff --git a/pandas/tests/io/pytables/test_select.py b/pandas/tests/io/pytables/test_select.py index b644c3420150c..a52118ee6437b 100644 --- a/pandas/tests/io/pytables/test_select.py +++ b/pandas/tests/io/pytables/test_select.py @@ -659,7 +659,7 @@ def test_frame_select_complex(setup_path): tm.assert_frame_equal(result, expected) -def test_frame_select_complex2(setup_path): +def test_frame_select_complex2(): with ensure_clean_path(["params.hdf", "hist.hdf"]) as paths: diff --git a/pandas/tests/io/test_fsspec.py b/pandas/tests/io/test_fsspec.py index f1040c0bd30f2..48d44ad79aae3 100644 --- a/pandas/tests/io/test_fsspec.py +++ b/pandas/tests/io/test_fsspec.py @@ -153,7 +153,7 @@ def test_excel_options(fsspectest, extension): @td.skip_if_no("fastparquet") -def test_to_parquet_new_file(monkeypatch, cleared_fs): +def test_to_parquet_new_file(cleared_fs): """Regression test for writing to a not-yet-existent GCS Parquet file.""" df1.to_parquet( "memory://test/test.csv", index=True, engine="fastparquet", compression=None diff --git a/pandas/tests/io/test_parquet.py b/pandas/tests/io/test_parquet.py index b57923093e3e8..126ff3c4bf7b8 100644 --- a/pandas/tests/io/test_parquet.py +++ b/pandas/tests/io/test_parquet.py @@ -353,7 +353,7 @@ def test_cross_engine_pa_fp(df_cross_compat, pa, fp): tm.assert_frame_equal(result, df[["a", "d"]]) -def test_cross_engine_fp_pa(request, df_cross_compat, pa, fp): +def test_cross_engine_fp_pa(df_cross_compat, pa, fp): # cross-compat with differing reading/writing engines df = df_cross_compat with tm.ensure_clean() as path: @@ -1135,7 +1135,7 @@ def test_timezone_aware_index(self, fp, timezone_aware_date_list): expected.index.name = "index" check_round_trip(df, fp, expected=expected) - def test_use_nullable_dtypes_not_supported(self, monkeypatch, fp): + def test_use_nullable_dtypes_not_supported(self, fp): df = pd.DataFrame({"a": [1, 2]}) with tm.ensure_clean() as path: