diff --git a/pandas/io/excel/_base.py b/pandas/io/excel/_base.py index 0b284fd4e9750..5e0ef4d6193f2 100644 --- a/pandas/io/excel/_base.py +++ b/pandas/io/excel/_base.py @@ -1592,9 +1592,9 @@ def __init__( xlrd_version = Version(get_version(xlrd)) - ext = None if engine is None: # Only determine ext if it is needed + ext: str | None if xlrd_version is not None and isinstance(path_or_buffer, xlrd.Book): ext = "xls" else: @@ -1611,32 +1611,6 @@ def __init__( if engine == "auto": engine = get_default_engine(ext, mode="reader") - if engine == "xlrd" and xlrd_version is not None: - if ext is None: - # Need ext to determine ext in order to raise/warn - if isinstance(path_or_buffer, xlrd.Book): - ext = "xls" - else: - ext = inspect_excel_format( - path_or_buffer, storage_options=storage_options - ) - - # Pass through if ext is None, otherwise check if ext valid for xlrd - if ext and ext != "xls" and xlrd_version >= Version("2"): - raise ValueError( - f"Your version of xlrd is {xlrd_version}. In xlrd >= 2.0, " - f"only the xls format is supported. Install openpyxl instead." - ) - elif ext and ext != "xls": - stacklevel = find_stack_level() - warnings.warn( - f"Your version of xlrd is {xlrd_version}. In xlrd >= 2.0, " - f"only the xls format is supported. Install " - f"openpyxl instead.", - FutureWarning, - stacklevel=stacklevel, - ) - assert engine is not None self.engine = engine self.storage_options = storage_options diff --git a/pandas/io/excel/_xlrd.py b/pandas/io/excel/_xlrd.py index 171705dee6e59..c556e4c68c6c0 100644 --- a/pandas/io/excel/_xlrd.py +++ b/pandas/io/excel/_xlrd.py @@ -30,7 +30,7 @@ def __init__( Object to be parsed. {storage_options} """ - err_msg = "Install xlrd >= 1.0.0 for Excel support" + err_msg = "Install xlrd >= 2.0.1 for xls Excel support" import_optional_dependency("xlrd", extra=err_msg) super().__init__(filepath_or_buffer, storage_options=storage_options) diff --git a/pandas/tests/io/excel/__init__.py b/pandas/tests/io/excel/__init__.py index 9136153101e23..419761cbe1d6d 100644 --- a/pandas/tests/io/excel/__init__.py +++ b/pandas/tests/io/excel/__init__.py @@ -9,8 +9,4 @@ pytest.mark.filterwarnings( "ignore:This method will be removed in future versions:DeprecationWarning" ), - # GH 38571 - pytest.mark.filterwarnings( - "ignore:.*In xlrd >= 2.0, only the xls format is supported:FutureWarning" - ), ] diff --git a/pandas/tests/io/excel/test_xlrd.py b/pandas/tests/io/excel/test_xlrd.py index 30dddbd7de50b..1f8fb4b801356 100644 --- a/pandas/tests/io/excel/test_xlrd.py +++ b/pandas/tests/io/excel/test_xlrd.py @@ -2,8 +2,6 @@ import pytest -from pandas.compat._optional import import_optional_dependency - import pandas as pd import pandas._testing as tm @@ -39,35 +37,13 @@ def test_read_xlrd_book(read_ext_xlrd, datapath): tm.assert_frame_equal(result, expected) -def test_excel_file_warning_with_xlsx_file(datapath): - # GH 29375 - path = datapath("io", "data", "excel", "test1.xlsx") - has_openpyxl = import_optional_dependency("openpyxl", errors="ignore") is not None - if not has_openpyxl: - with tm.assert_produces_warning( - FutureWarning, - raise_on_extra_warnings=False, - match="The xlrd engine is no longer maintained", - ): - ExcelFile(path, engine=None) - else: - with tm.assert_produces_warning(None): - pd.read_excel(path, "Sheet1", engine=None) - - -def test_read_excel_warning_with_xlsx_file(datapath): +def test_read_xlsx_fails(datapath): # GH 29375 + from xlrd.biffh import XLRDError + path = datapath("io", "data", "excel", "test1.xlsx") - has_openpyxl = import_optional_dependency("openpyxl", errors="ignore") is not None - if not has_openpyxl: - with pytest.raises( - ValueError, - match="Your version of xlrd is ", - ): - pd.read_excel(path, "Sheet1", engine=None) - else: - with tm.assert_produces_warning(None): - pd.read_excel(path, "Sheet1", engine=None) + with pytest.raises(XLRDError, match="Excel xlsx file; not supported"): + pd.read_excel(path, engine="xlrd") @pytest.mark.parametrize(