Skip to content

Commit 4569269

Browse files
authored
CLN: dont depend on fixture implementation details (#44645)
1 parent 3c6aded commit 4569269

File tree

1 file changed

+28
-34
lines changed

1 file changed

+28
-34
lines changed

pandas/tests/io/excel/test_readers.py

+28-34
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ def _transfer_marks(engine, read_ext):
9090

9191

9292
@pytest.fixture(
93-
autouse=True,
9493
params=[
9594
_transfer_marks(eng, ext)
9695
for eng in engine_params
@@ -172,7 +171,7 @@ def test_usecols_int(self, read_ext, df_ref):
172171
)
173172

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

198197
def test_usecols_str(self, request, read_ext, df_ref):
199-
if pd.read_excel.keywords["engine"] == "pyxlsb":
198+
if read_ext == ".xlsb":
200199
request.node.add_marker(
201200
pytest.mark.xfail(
202201
reason="Sheets containing datetimes not supported by pyxlsb"
@@ -254,7 +253,7 @@ def test_usecols_str(self, request, read_ext, df_ref):
254253
def test_usecols_diff_positional_int_columns_order(
255254
self, request, read_ext, usecols, df_ref
256255
):
257-
if pd.read_excel.keywords["engine"] == "pyxlsb":
256+
if read_ext == ".xlsb":
258257
request.node.add_marker(
259258
pytest.mark.xfail(
260259
reason="Sheets containing datetimes not supported by pyxlsb"
@@ -276,7 +275,7 @@ def test_usecols_diff_positional_str_columns_order(self, read_ext, usecols, df_r
276275
tm.assert_frame_equal(result, expected, check_names=False)
277276

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

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

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

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

403402
def test_reader_special_dtypes(self, request, read_ext):
404-
if pd.read_excel.keywords["engine"] == "pyxlsb":
403+
if read_ext == ".xlsb":
405404
request.node.add_marker(
406405
pytest.mark.xfail(
407406
reason="Sheets containing datetimes not supported by pyxlsb"
@@ -610,9 +609,8 @@ def test_reader_spaces(self, read_ext):
610609
("gh-36122", DataFrame(columns=["got 2nd sa"])),
611610
],
612611
)
613-
def test_read_excel_ods_nested_xml(self, read_ext, basename, expected):
612+
def test_read_excel_ods_nested_xml(self, engine, read_ext, basename, expected):
614613
# see gh-35802
615-
engine = pd.read_excel.keywords["engine"]
616614
if engine != "odf":
617615
pytest.skip(f"Skipped for engine: {engine}")
618616

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

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

686-
if pd.read_excel.keywords["engine"] == "openpyxl":
684+
if engine == "openpyxl":
687685
request.node.add_marker(
688686
pytest.mark.xfail(reason="Maybe not supported by openpyxl")
689687
)
690688

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

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

866-
def test_reader_seconds(self, request, read_ext):
867-
if pd.read_excel.keywords["engine"] == "pyxlsb":
864+
def test_reader_seconds(self, request, engine, read_ext):
865+
if engine == "pyxlsb":
868866
request.node.add_marker(
869867
pytest.mark.xfail(
870868
reason="Sheets containing datetimes not supported by pyxlsb"
@@ -898,7 +896,7 @@ def test_reader_seconds(self, request, read_ext):
898896

899897
def test_read_excel_multiindex(self, request, read_ext):
900898
# see gh-4679
901-
if pd.read_excel.keywords["engine"] == "pyxlsb":
899+
if read_ext == ".xlsb":
902900
request.node.add_marker(
903901
pytest.mark.xfail(
904902
reason="Sheets containing datetimes not supported by pyxlsb"
@@ -993,7 +991,7 @@ def test_read_excel_multiindex_blank_after_name(
993991
self, request, read_ext, sheet_name, idx_lvl2
994992
):
995993
# GH34673
996-
if pd.read_excel.keywords["engine"] == "pyxlsb":
994+
if read_ext == ".xlsb":
997995
request.node.add_marker(
998996
pytest.mark.xfail(
999997
reason="Sheets containing datetimes not supported by pyxlsb (GH4679"
@@ -1115,7 +1113,7 @@ def test_read_excel_bool_header_arg(self, read_ext):
11151113

11161114
def test_read_excel_skiprows(self, request, read_ext):
11171115
# GH 4903
1118-
if pd.read_excel.keywords["engine"] == "pyxlsb":
1116+
if read_ext == ".xlsb":
11191117
request.node.add_marker(
11201118
pytest.mark.xfail(
11211119
reason="Sheets containing datetimes not supported by pyxlsb"
@@ -1261,11 +1259,11 @@ def test_trailing_blanks(self, read_ext):
12611259
result = pd.read_excel(file_name)
12621260
assert result.shape == (3, 3)
12631261

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

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

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

14281424
def test_sheet_name(self, request, read_ext, df_ref):
1429-
# For some reason pd.read_excel has no attribute 'keywords' here.
1430-
# Skipping based on read_ext instead.
14311425
if read_ext == ".xlsb":
14321426
request.node.add_marker(
14331427
pytest.mark.xfail(
@@ -1505,7 +1499,7 @@ def test_excel_read_binary_via_read_excel(self, read_ext, engine):
15051499
xlrd_version is not None and xlrd_version >= Version("2"),
15061500
reason="xlrd no longer supports xlsx",
15071501
)
1508-
def test_excel_high_surrogate(self, engine):
1502+
def test_excel_high_surrogate(self):
15091503
# GH 23809
15101504
expected = DataFrame(["\udc88"], columns=["Column1"])
15111505

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

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

1569-
def test_corrupt_files_closed(self, request, engine, read_ext):
1563+
def test_corrupt_files_closed(self, engine, read_ext):
15701564
# GH41778
15711565
errors = (BadZipFile,)
15721566
if engine is None:

0 commit comments

Comments
 (0)