Skip to content

TST: Remove unused fixtures in tests #45843

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pandas/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/apply/test_str.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/frame/indexing/test_where.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/frame/methods/test_shift.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 0 additions & 3 deletions pandas/tests/indexes/period/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/indexing/test_loc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
78 changes: 41 additions & 37 deletions pandas/tests/io/json/test_json_table_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand All @@ -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):
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions pandas/tests/io/parser/test_parse_dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
16 changes: 1 addition & 15 deletions pandas/tests/io/pytables/test_round_trip.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/io/pytables/test_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/io/test_fsspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/io/test_parquet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down