Skip to content

Commit 8252d3b

Browse files
Add more supported extensions to engines in ExcelFile. Reflect changes on the documentation
1 parent fadb59b commit 8252d3b

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

pandas/io/excel/_base.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"""
3535
Read an Excel file into a pandas DataFrame.
3636
37-
Supports `xls`, `xlsx`, `xlsm`, `xlsb`, and `odf` file extensions
37+
Supports `xls`, `xlsx`, `xlsm`, `xlsb`, `odf`, `ods` and `odt` file extensions
3838
read from a local filesystem or URL. Supports an option to read
3939
a single sheet or a list of sheets.
4040
@@ -105,9 +105,9 @@
105105
If io is not a buffer or path, this must be set to identify io.
106106
Acceptable values are None, "auto", "xlrd", "openpyxl", "odf", or "pyxlsb".
107107
File compatibility:
108-
"xlrd" engine supports .xls, and .xlsx files.
109-
"openpyxl" engine supports .xlsx, .xlsm, .xltx, and .xltm files.
110-
"odf" engine supports .odf files.
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.
111111
"pyxlsb" engine supports .xlsb files.
112112
converters : dict, default None
113113
Dict of functions for converting values in certain columns. Keys can
@@ -802,9 +802,9 @@ class ExcelFile:
802802
Acceptable values are None, ``auto``, ``xlrd``, ``openpyxl``,
803803
``odf``, or ``pyxlsb``.
804804
File compatibility:
805-
``xlrd`` engine supports .xls, and .xlsx files.
806-
``openpyxl`` engine supports .xlsx, .xlsm, .xltx, and .xltm files.
807-
``odf`` engine supports .odf files.
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.
808808
``pyxlsb`` engine supports .xlsb files.
809809
"""
810810

@@ -820,10 +820,12 @@ 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.
823825
_supported_engine_filetypes = {
824-
"xlrd": ["xls", "xlsx"],
826+
"xlrd": ["xls", "xlsx", "xlsm"],
825827
"openpyxl": ["xlsx", "xlsm", "xltx", "xltm"],
826-
"odf": ["odf"],
828+
"odf": ["odf", "ods", "odt"],
827829
"pyxlsb": ["xlsb"],
828830
}
829831

@@ -834,13 +836,15 @@ def __init__(self, io, engine=None):
834836
raise ValueError(f"Unknown engine: {engine}")
835837

836838
self.engine = engine
837-
# could be a str, ExcelFile, Book, etc.
839+
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)
838845
self.io = io
839846
# Always a string
840847
self._io = stringify_path(io)
841-
# Check engine-extension compatibility
842-
ext = os.path.splitext(io)[-1][1:]
843-
self.check_extension(engine, ext)
844848

845849
self._reader = self._engines[engine](self._io)
846850

0 commit comments

Comments
 (0)