Skip to content

CLN: dont depend on fixture implementation details #44645

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
Nov 28, 2021
Merged
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
62 changes: 28 additions & 34 deletions pandas/tests/io/excel/test_readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ def _transfer_marks(engine, read_ext):


@pytest.fixture(
autouse=True,
params=[
_transfer_marks(eng, ext)
for eng in engine_params
Expand Down Expand Up @@ -172,7 +171,7 @@ def test_usecols_int(self, read_ext, df_ref):
)

def test_usecols_list(self, request, read_ext, df_ref):
if pd.read_excel.keywords["engine"] == "pyxlsb":
if read_ext == ".xlsb":
request.node.add_marker(
pytest.mark.xfail(
reason="Sheets containing datetimes not supported by pyxlsb"
Expand All @@ -196,7 +195,7 @@ def test_usecols_list(self, request, read_ext, df_ref):
tm.assert_frame_equal(df2, df_ref, check_names=False)

def test_usecols_str(self, request, read_ext, df_ref):
if pd.read_excel.keywords["engine"] == "pyxlsb":
if read_ext == ".xlsb":
request.node.add_marker(
pytest.mark.xfail(
reason="Sheets containing datetimes not supported by pyxlsb"
Expand Down Expand Up @@ -254,7 +253,7 @@ def test_usecols_str(self, request, read_ext, df_ref):
def test_usecols_diff_positional_int_columns_order(
self, request, read_ext, usecols, df_ref
):
if pd.read_excel.keywords["engine"] == "pyxlsb":
if read_ext == ".xlsb":
request.node.add_marker(
pytest.mark.xfail(
reason="Sheets containing datetimes not supported by pyxlsb"
Expand All @@ -276,7 +275,7 @@ def test_usecols_diff_positional_str_columns_order(self, read_ext, usecols, df_r
tm.assert_frame_equal(result, expected, check_names=False)

def test_read_excel_without_slicing(self, request, read_ext, df_ref):
if pd.read_excel.keywords["engine"] == "pyxlsb":
if read_ext == ".xlsb":
request.node.add_marker(
pytest.mark.xfail(
reason="Sheets containing datetimes not supported by pyxlsb"
Expand All @@ -288,7 +287,7 @@ def test_read_excel_without_slicing(self, request, read_ext, df_ref):
tm.assert_frame_equal(result, expected, check_names=False)

def test_usecols_excel_range_str(self, request, read_ext, df_ref):
if pd.read_excel.keywords["engine"] == "pyxlsb":
if read_ext == ".xlsb":
request.node.add_marker(
pytest.mark.xfail(
reason="Sheets containing datetimes not supported by pyxlsb"
Expand Down Expand Up @@ -368,7 +367,7 @@ def test_excel_stop_iterator(self, read_ext):
tm.assert_frame_equal(parsed, expected)

def test_excel_cell_error_na(self, request, read_ext):
if pd.read_excel.keywords["engine"] == "pyxlsb":
if read_ext == ".xlsb":
request.node.add_marker(
pytest.mark.xfail(
reason="Sheets containing datetimes not supported by pyxlsb"
Expand All @@ -380,7 +379,7 @@ def test_excel_cell_error_na(self, request, read_ext):
tm.assert_frame_equal(parsed, expected)

def test_excel_table(self, request, read_ext, df_ref):
if pd.read_excel.keywords["engine"] == "pyxlsb":
if read_ext == ".xlsb":
request.node.add_marker(
pytest.mark.xfail(
reason="Sheets containing datetimes not supported by pyxlsb"
Expand All @@ -401,7 +400,7 @@ def test_excel_table(self, request, read_ext, df_ref):
tm.assert_frame_equal(df3, df1.iloc[:-1])

def test_reader_special_dtypes(self, request, read_ext):
if pd.read_excel.keywords["engine"] == "pyxlsb":
if read_ext == ".xlsb":
request.node.add_marker(
pytest.mark.xfail(
reason="Sheets containing datetimes not supported by pyxlsb"
Expand Down Expand Up @@ -610,9 +609,8 @@ def test_reader_spaces(self, read_ext):
("gh-36122", DataFrame(columns=["got 2nd sa"])),
],
)
def test_read_excel_ods_nested_xml(self, read_ext, basename, expected):
def test_read_excel_ods_nested_xml(self, engine, read_ext, basename, expected):
# see gh-35802
engine = pd.read_excel.keywords["engine"]
if engine != "odf":
pytest.skip(f"Skipped for engine: {engine}")

Expand Down Expand Up @@ -665,9 +663,9 @@ def test_read_excel_blank_with_header(self, read_ext):
actual = pd.read_excel("blank_with_header" + read_ext, sheet_name="Sheet1")
tm.assert_frame_equal(actual, expected)

def test_date_conversion_overflow(self, request, read_ext):
def test_date_conversion_overflow(self, request, engine, read_ext):
# GH 10001 : pandas.ExcelFile ignore parse_dates=False
if pd.read_excel.keywords["engine"] == "pyxlsb":
if engine == "pyxlsb":
request.node.add_marker(
pytest.mark.xfail(
reason="Sheets containing datetimes not supported by pyxlsb"
Expand All @@ -683,12 +681,12 @@ def test_date_conversion_overflow(self, request, read_ext):
columns=["DateColWithBigInt", "StringCol"],
)

if pd.read_excel.keywords["engine"] == "openpyxl":
if engine == "openpyxl":
request.node.add_marker(
pytest.mark.xfail(reason="Maybe not supported by openpyxl")
)

if pd.read_excel.keywords["engine"] is None and read_ext in (".xlsx", ".xlsm"):
if engine is None and read_ext in (".xlsx", ".xlsm"):
# GH 35029
request.node.add_marker(
pytest.mark.xfail(reason="Defaults to openpyxl, maybe not supported")
Expand All @@ -698,7 +696,7 @@ def test_date_conversion_overflow(self, request, read_ext):
tm.assert_frame_equal(result, expected)

def test_sheet_name(self, request, read_ext, df_ref):
if pd.read_excel.keywords["engine"] == "pyxlsb":
if read_ext == ".xlsb":
request.node.add_marker(
pytest.mark.xfail(
reason="Sheets containing datetimes not supported by pyxlsb"
Expand Down Expand Up @@ -863,8 +861,8 @@ def test_close_from_py_localpath(self, read_ext):
# should not throw an exception because the passed file was closed
f.read()

def test_reader_seconds(self, request, read_ext):
if pd.read_excel.keywords["engine"] == "pyxlsb":
def test_reader_seconds(self, request, engine, read_ext):
if engine == "pyxlsb":
request.node.add_marker(
pytest.mark.xfail(
reason="Sheets containing datetimes not supported by pyxlsb"
Expand Down Expand Up @@ -898,7 +896,7 @@ def test_reader_seconds(self, request, read_ext):

def test_read_excel_multiindex(self, request, read_ext):
# see gh-4679
if pd.read_excel.keywords["engine"] == "pyxlsb":
if read_ext == ".xlsb":
request.node.add_marker(
pytest.mark.xfail(
reason="Sheets containing datetimes not supported by pyxlsb"
Expand Down Expand Up @@ -993,7 +991,7 @@ def test_read_excel_multiindex_blank_after_name(
self, request, read_ext, sheet_name, idx_lvl2
):
# GH34673
if pd.read_excel.keywords["engine"] == "pyxlsb":
if read_ext == ".xlsb":
request.node.add_marker(
pytest.mark.xfail(
reason="Sheets containing datetimes not supported by pyxlsb (GH4679"
Expand Down Expand Up @@ -1115,7 +1113,7 @@ def test_read_excel_bool_header_arg(self, read_ext):

def test_read_excel_skiprows(self, request, read_ext):
# GH 4903
if pd.read_excel.keywords["engine"] == "pyxlsb":
if read_ext == ".xlsb":
request.node.add_marker(
pytest.mark.xfail(
reason="Sheets containing datetimes not supported by pyxlsb"
Expand Down Expand Up @@ -1261,11 +1259,11 @@ def test_trailing_blanks(self, read_ext):
result = pd.read_excel(file_name)
assert result.shape == (3, 3)

def test_ignore_chartsheets_by_str(self, request, read_ext):
def test_ignore_chartsheets_by_str(self, request, engine, read_ext):
# GH 41448
if pd.read_excel.keywords["engine"] == "odf":
if engine == "odf":
pytest.skip("chartsheets do not exist in the ODF format")
if pd.read_excel.keywords["engine"] == "pyxlsb":
if engine == "pyxlsb":
request.node.add_marker(
pytest.mark.xfail(
reason="pyxlsb can't distinguish chartsheets from worksheets"
Expand All @@ -1274,11 +1272,11 @@ def test_ignore_chartsheets_by_str(self, request, read_ext):
with pytest.raises(ValueError, match="Worksheet named 'Chart1' not found"):
pd.read_excel("chartsheet" + read_ext, sheet_name="Chart1")

def test_ignore_chartsheets_by_int(self, request, read_ext):
def test_ignore_chartsheets_by_int(self, request, engine, read_ext):
# GH 41448
if pd.read_excel.keywords["engine"] == "odf":
if engine == "odf":
pytest.skip("chartsheets do not exist in the ODF format")
if pd.read_excel.keywords["engine"] == "pyxlsb":
if engine == "pyxlsb":
request.node.add_marker(
pytest.mark.xfail(
reason="pyxlsb can't distinguish chartsheets from worksheets"
Expand Down Expand Up @@ -1395,8 +1393,6 @@ def test_excel_passes_na_filter(self, read_ext, na_filter):
tm.assert_frame_equal(parsed, expected)

def test_excel_table_sheet_by_index(self, request, read_ext, df_ref):
# For some reason pd.read_excel has no attribute 'keywords' here.
# Skipping based on read_ext instead.
if read_ext == ".xlsb":
request.node.add_marker(
pytest.mark.xfail(
Expand Down Expand Up @@ -1426,8 +1422,6 @@ def test_excel_table_sheet_by_index(self, request, read_ext, df_ref):
tm.assert_frame_equal(df3, df1.iloc[:-1])

def test_sheet_name(self, request, read_ext, df_ref):
# For some reason pd.read_excel has no attribute 'keywords' here.
# Skipping based on read_ext instead.
if read_ext == ".xlsb":
request.node.add_marker(
pytest.mark.xfail(
Expand Down Expand Up @@ -1505,7 +1499,7 @@ def test_excel_read_binary_via_read_excel(self, read_ext, engine):
xlrd_version is not None and xlrd_version >= Version("2"),
reason="xlrd no longer supports xlsx",
)
def test_excel_high_surrogate(self, engine):
def test_excel_high_surrogate(self):
# GH 23809
expected = DataFrame(["\udc88"], columns=["Column1"])

Expand All @@ -1514,7 +1508,7 @@ def test_excel_high_surrogate(self, engine):
tm.assert_frame_equal(expected, actual)

@pytest.mark.parametrize("filename", ["df_empty.xlsx", "df_equals.xlsx"])
def test_header_with_index_col(self, engine, filename):
def test_header_with_index_col(self, filename):
# GH 33476
idx = Index(["Z"], name="I2")
cols = MultiIndex.from_tuples([("A", "B"), ("A", "B.1")], names=["I11", "I12"])
Expand Down Expand Up @@ -1566,7 +1560,7 @@ def test_ignore_chartsheets(self, request, engine, read_ext):
with pd.ExcelFile("chartsheet" + read_ext) as excel:
assert excel.sheet_names == ["Sheet1"]

def test_corrupt_files_closed(self, request, engine, read_ext):
def test_corrupt_files_closed(self, engine, read_ext):
# GH41778
errors = (BadZipFile,)
if engine is None:
Expand Down