Skip to content

Commit 6deb48b

Browse files
Guilherme Beltraminialanbato
Guilherme Beltramini
authored andcommitted
ERR: Raise ImportError when xlrd is not present
Related issues: pandas-dev#8515, pandas-dev#14673 Author: Guilherme Beltramini <[email protected]> Closes pandas-dev#17613 from gcbeltramini/xlrd-import and squashes the following commits: dee1998 [Guilherme Beltramini] Add PR number and blank line c2759cb [Guilherme Beltramini] Throw ImportError
1 parent 629bff8 commit 6deb48b

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

doc/source/whatsnew/v0.21.0.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ Other Enhancements
116116
- :func:`Styler.where` has been implemented. It is as a convenience for :func:`Styler.applymap` and enables simple DataFrame styling on the Jupyter notebook (:issue:`17474`).
117117
- :func:`MultiIndex.is_monotonic_decreasing` has been implemented. Previously returned ``False`` in all cases. (:issue:`16554`)
118118
- :func:`Categorical.rename_categories` now accepts a dict-like argument as `new_categories` and only updates the categories found in that dict. (:issue:`17336`)
119+
- :func:`read_excel` raises ``ImportError`` with a better message if ``xlrd`` is not installed. (:issue:`17613`)
119120

120121

121122
.. _whatsnew_0210.api_breaking:
@@ -523,7 +524,7 @@ I/O
523524
- Bug in :func:`read_stata` where the index was not set (:issue:`16342`)
524525
- Bug in :func:`read_html` where import check fails when run in multiple threads (:issue:`16928`)
525526
- Bug in :func:`read_csv` where automatic delimiter detection caused a ``TypeError`` to be thrown when a bad line was encountered rather than the correct error message (:issue:`13374`)
526-
- Bug in ``DataFrame.to_html()`` with ``notebook=True`` where DataFrames with named indices or non-MultiIndex indices had undesired horizontal or vertical alignment for column or row labels, respectively (:issue:`16792`)
527+
- Bug in ``DataFrame.to_html()`` with ``notebook=True`` where DataFrames with named indices or non-MultiIndex indices had undesired horizontal or vertical alignment for column or row labels, respectively (:issue:`16792`)
527528

528529
Plotting
529530
^^^^^^^^

pandas/io/excel.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -239,12 +239,17 @@ class ExcelFile(object):
239239

240240
def __init__(self, io, **kwds):
241241

242-
import xlrd # throw an ImportError if we need to
242+
err_msg = "Install xlrd >= 0.9.0 for Excel support"
243243

244-
ver = tuple(map(int, xlrd.__VERSION__.split(".")[:2]))
245-
if ver < (0, 9): # pragma: no cover
246-
raise ImportError("pandas requires xlrd >= 0.9.0 for excel "
247-
"support, current version " + xlrd.__VERSION__)
244+
try:
245+
import xlrd
246+
except ImportError:
247+
raise ImportError(err_msg)
248+
else:
249+
ver = tuple(map(int, xlrd.__VERSION__.split(".")[:2]))
250+
if ver < (0, 9): # pragma: no cover
251+
raise ImportError(err_msg +
252+
". Current version " + xlrd.__VERSION__)
248253

249254
# could be a str, ExcelFile, Book, etc.
250255
self.io = io

0 commit comments

Comments
 (0)