Skip to content

Commit d4eb433

Browse files
Remove filetype compatibility check for ExcelFile. Remove whatsnew entry. Clarifications in the ExcelFile and read_excel docs.
1 parent f71193e commit d4eb433

File tree

2 files changed

+13
-53
lines changed

2 files changed

+13
-53
lines changed

doc/source/whatsnew/v1.1.0.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,6 @@ Other enhancements
236236
and :class:`~pandas.io.stata.StataWriterUTF8` (:issue:`26599`).
237237
- :meth:`HDFStore.put` now accepts `track_times` parameter. Parameter is passed to ``create_table`` method of ``PyTables`` (:issue:`32682`).
238238
- Make :class:`pandas.core.window.Rolling` and :class:`pandas.core.window.Expanding` iterable(:issue:`11704`)
239-
- :meth:`read_excel` now checks if the engine passed as an argument can process the file provided and outputs a suggestion if it cannot (:issue:`34237`).
240239

241240
.. ---------------------------------------------------------------------------
242241

pandas/io/excel/_base.py

Lines changed: 13 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,12 @@
103103
of dtype conversion.
104104
engine : str, default None
105105
If io is not a buffer or path, this must be set to identify io.
106-
Acceptable values are None, "auto", "xlrd", "openpyxl", "odf", or "pyxlsb".
106+
Acceptable values are None, "xlrd", "openpyxl", "odf", or "pyxlsb".
107107
File compatibility:
108-
"xlrd" engine supports .xls, .xlsx, and .xlsm files.
109-
"openpyxl" engine supports .xlsx, and .xlsm files.
110-
"odf" engine supports .odf, .ods, and .odt files.
111-
"pyxlsb" engine supports .xlsb files.
108+
"xlrd" supports most old/new Excel file formats.
109+
"openpyxl" engine supports newer Excel file formats.
110+
"odf" engine supports OpenDocument file formats (.odf, .ods, .odt).
111+
"pyxlsb" engine supports Binary Excel files.
112112
converters : dict, default None
113113
Dict of functions for converting values in certain columns. Keys can
114114
either be integers or column labels, values are functions that take one
@@ -789,23 +789,23 @@ def close(self):
789789
class ExcelFile:
790790
"""
791791
Class for parsing tabular excel sheets into DataFrame objects.
792-
Uses xlrd. See read_excel for more documentation
792+
Uses xlrd by default. See read_excel for more documentation
793793
794794
Parameters
795795
----------
796796
io : str, path object (pathlib.Path or py._path.local.LocalPath),
797797
a file-like object, xlrd workbook or openpypl workbook.
798798
If a string or path object, expected to be a path to a
799-
.xls, .xlsx, .xlsb, .xlsm, .xltx, .xltm or .odf file.
799+
.xls, .xlsx, .xlsb, .xlsm, .odf, .ods, or .odt file.
800800
engine : str, default None
801801
If io is not a buffer or path, this must be set to identify io.
802-
Acceptable values are None, ``auto``, ``xlrd``, ``openpyxl``,
802+
Acceptable values are None, ``xlrd``, ``openpyxl``,
803803
``odf``, or ``pyxlsb``.
804804
File compatibility:
805-
``xlrd`` engine supports .xls, .xlsx, and .xlsm files.
806-
``openpyxl`` engine supports .xlsx, and .xlsm files.
807-
``odf`` engine supports .odf, .ods, and .odt files.
808-
``pyxlsb`` engine supports .xlsb files.
805+
``xlrd`` supports most old/new Excel file formats.
806+
``openpyxl`` engine supports newer Excel file formats.
807+
``odf`` engine supports OpenDocument file formats (.odf, .ods, .odt).
808+
``pyxlsb`` engine supports Binary Excel files.
809809
"""
810810

811811
from pandas.io.excel._odfreader import _ODFReader
@@ -820,15 +820,6 @@ class ExcelFile:
820820
"pyxlsb": _PyxlsbReader,
821821
}
822822

823-
# Excel templates are not supported by read_excel according to the
824-
# documentation, but openpyxl specifies them as supported.
825-
_supported_engine_filetypes = {
826-
"xlrd": ["xls", "xlsx", "xlsm"],
827-
"openpyxl": ["xlsx", "xlsm", "xltx", "xltm"],
828-
"odf": ["odf", "ods", "odt"],
829-
"pyxlsb": ["xlsb"],
830-
}
831-
832823
def __init__(self, io, engine=None):
833824
if engine is None:
834825
engine = "xlrd"
@@ -837,11 +828,7 @@ def __init__(self, io, engine=None):
837828

838829
self.engine = engine
839830

840-
# 'io' could be a str, ExcelFile, Book, etc.
841-
if isinstance(io, str):
842-
# Check engine-extension compatibility
843-
ext = os.path.splitext(io)[-1][1:]
844-
self.check_extension(engine, ext)
831+
# Could be a str, ExcelFile, Book, etc.
845832
self.io = io
846833
# Always a string
847834
self._io = stringify_path(io)
@@ -921,32 +908,6 @@ def book(self):
921908
def sheet_names(self):
922909
return self._reader.sheet_names
923910

924-
@classmethod
925-
def check_extension(cls, engine, ext):
926-
"""
927-
checks that the provided path's extension is supported by the reader engine.
928-
If it isn't supported, raises a ValueError.
929-
"""
930-
if ext.startswith("."):
931-
ext = ext[1:]
932-
if ext not in cls._supported_engine_filetypes.get(engine):
933-
supporting_engines = [
934-
k for k, v in cls._supported_engine_filetypes.items() if ext in v
935-
]
936-
if not supporting_engines:
937-
eng_info = " No engines currently support the provided file extension."
938-
else:
939-
eng_info = (
940-
" Use engine(s) "
941-
+ ", ".join("'{0}'".format(e) for e in supporting_engines)
942-
+ " instead."
943-
)
944-
raise ValueError(
945-
f"Unsupported extension for engine '{engine}': '.{ext}'." + eng_info
946-
)
947-
else:
948-
return True
949-
950911
def close(self):
951912
"""close io if necessary"""
952913
self._reader.close()

0 commit comments

Comments
 (0)