Skip to content

Commit 942c56c

Browse files
committed
Deprecate using xlrd engine
1 parent b657045 commit 942c56c

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

pandas/io/excel/_base.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from io import BytesIO
55
import os
66
from textwrap import fill
7+
import warnings
78

89
from pandas._config import config
910

@@ -791,7 +792,7 @@ def close(self):
791792
class ExcelFile:
792793
"""
793794
Class for parsing tabular excel sheets into DataFrame objects.
794-
Uses xlrd. See read_excel for more documentation
795+
Uses xlrd, openpyxl or odf. See read_excel for more documentation
795796
796797
Parameters
797798
----------
@@ -811,8 +812,14 @@ class ExcelFile:
811812
_engines = {"xlrd": _XlrdReader, "openpyxl": _OpenpyxlReader, "odf": _ODFReader}
812813

813814
def __init__(self, io, engine=None):
814-
if engine is None:
815+
if engine == "xlrd" or engine is None:
815816
engine = "xlrd"
817+
warnings.warn(
818+
"xlrd is deprecated and will be removed in a future "
819+
"version. Use 'openpyxl' or 'odf' instead.",
820+
FutureWarning,
821+
stacklevel=2,
822+
)
816823
if engine not in self._engines:
817824
raise ValueError("Unknown engine: {engine}".format(engine=engine))
818825

pandas/tests/io/excel/test_xlrd.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,12 @@ def test_excel_table_sheet_by_index(datapath, read_ext):
3939
with pd.ExcelFile(path) as excel:
4040
with pytest.raises(xlrd.XLRDError):
4141
pd.read_excel(excel, "asdf")
42+
43+
44+
def test_read_excel_with_default(datapath):
45+
path = datapath("io", "data", "test1.xls")
46+
with tm.assert_produces_warning(
47+
FutureWarning, check_stacklevel=False, raise_on_extra_warnings=False
48+
):
49+
with pd.ExcelFile(path) as excel:
50+
pd.read_excel(excel, "Sheet1")

0 commit comments

Comments
 (0)