Skip to content

Commit cb43a81

Browse files
CLN: Remove xlrd < 2.0 code (#49376)
* CLN: Remove xlrd < 2.0 code * Add test * Add warning * Fix type-hint * Update pandas/io/excel/_xlrd.py Co-authored-by: Matthew Roeschke <[email protected]> * Remove warning * Remove warnings in tests * Remove filter Co-authored-by: Matthew Roeschke <[email protected]>
1 parent c044554 commit cb43a81

File tree

4 files changed

+7
-61
lines changed

4 files changed

+7
-61
lines changed

pandas/io/excel/_base.py

+1-27
Original file line numberDiff line numberDiff line change
@@ -1592,9 +1592,9 @@ def __init__(
15921592

15931593
xlrd_version = Version(get_version(xlrd))
15941594

1595-
ext = None
15961595
if engine is None:
15971596
# Only determine ext if it is needed
1597+
ext: str | None
15981598
if xlrd_version is not None and isinstance(path_or_buffer, xlrd.Book):
15991599
ext = "xls"
16001600
else:
@@ -1611,32 +1611,6 @@ def __init__(
16111611
if engine == "auto":
16121612
engine = get_default_engine(ext, mode="reader")
16131613

1614-
if engine == "xlrd" and xlrd_version is not None:
1615-
if ext is None:
1616-
# Need ext to determine ext in order to raise/warn
1617-
if isinstance(path_or_buffer, xlrd.Book):
1618-
ext = "xls"
1619-
else:
1620-
ext = inspect_excel_format(
1621-
path_or_buffer, storage_options=storage_options
1622-
)
1623-
1624-
# Pass through if ext is None, otherwise check if ext valid for xlrd
1625-
if ext and ext != "xls" and xlrd_version >= Version("2"):
1626-
raise ValueError(
1627-
f"Your version of xlrd is {xlrd_version}. In xlrd >= 2.0, "
1628-
f"only the xls format is supported. Install openpyxl instead."
1629-
)
1630-
elif ext and ext != "xls":
1631-
stacklevel = find_stack_level()
1632-
warnings.warn(
1633-
f"Your version of xlrd is {xlrd_version}. In xlrd >= 2.0, "
1634-
f"only the xls format is supported. Install "
1635-
f"openpyxl instead.",
1636-
FutureWarning,
1637-
stacklevel=stacklevel,
1638-
)
1639-
16401614
assert engine is not None
16411615
self.engine = engine
16421616
self.storage_options = storage_options

pandas/io/excel/_xlrd.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def __init__(
3030
Object to be parsed.
3131
{storage_options}
3232
"""
33-
err_msg = "Install xlrd >= 1.0.0 for Excel support"
33+
err_msg = "Install xlrd >= 2.0.1 for xls Excel support"
3434
import_optional_dependency("xlrd", extra=err_msg)
3535
super().__init__(filepath_or_buffer, storage_options=storage_options)
3636

pandas/tests/io/excel/__init__.py

-4
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,4 @@
99
pytest.mark.filterwarnings(
1010
"ignore:This method will be removed in future versions:DeprecationWarning"
1111
),
12-
# GH 38571
13-
pytest.mark.filterwarnings(
14-
"ignore:.*In xlrd >= 2.0, only the xls format is supported:FutureWarning"
15-
),
1612
]

pandas/tests/io/excel/test_xlrd.py

+5-29
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import pytest
44

5-
from pandas.compat._optional import import_optional_dependency
6-
75
import pandas as pd
86
import pandas._testing as tm
97

@@ -39,35 +37,13 @@ def test_read_xlrd_book(read_ext_xlrd, datapath):
3937
tm.assert_frame_equal(result, expected)
4038

4139

42-
def test_excel_file_warning_with_xlsx_file(datapath):
43-
# GH 29375
44-
path = datapath("io", "data", "excel", "test1.xlsx")
45-
has_openpyxl = import_optional_dependency("openpyxl", errors="ignore") is not None
46-
if not has_openpyxl:
47-
with tm.assert_produces_warning(
48-
FutureWarning,
49-
raise_on_extra_warnings=False,
50-
match="The xlrd engine is no longer maintained",
51-
):
52-
ExcelFile(path, engine=None)
53-
else:
54-
with tm.assert_produces_warning(None):
55-
pd.read_excel(path, "Sheet1", engine=None)
56-
57-
58-
def test_read_excel_warning_with_xlsx_file(datapath):
40+
def test_read_xlsx_fails(datapath):
5941
# GH 29375
42+
from xlrd.biffh import XLRDError
43+
6044
path = datapath("io", "data", "excel", "test1.xlsx")
61-
has_openpyxl = import_optional_dependency("openpyxl", errors="ignore") is not None
62-
if not has_openpyxl:
63-
with pytest.raises(
64-
ValueError,
65-
match="Your version of xlrd is ",
66-
):
67-
pd.read_excel(path, "Sheet1", engine=None)
68-
else:
69-
with tm.assert_produces_warning(None):
70-
pd.read_excel(path, "Sheet1", engine=None)
45+
with pytest.raises(XLRDError, match="Excel xlsx file; not supported"):
46+
pd.read_excel(path, engine="xlrd")
7147

7248

7349
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)