Closed
Description
If you run the tests/io/excel/test_readers.py
with only openpyxl installed, the xlrd tests are skipped, but some of the openpyxl tests still fail on needing xlrd.
eg:
____________________________________________________________ TestExcelFileRead.test_read_excel_engine_value[openpyxl-.xlsm-None] _____________________________________________________________
self = <pandas.tests.io.excel.test_readers.TestExcelFileRead object at 0x7fca3bb6d198>, read_ext = '.xlsm', excel_engine = None
@pytest.mark.parametrize('excel_engine', [
'xlrd',
None
])
def test_read_excel_engine_value(self, read_ext, excel_engine):
# GH 26566
> xl = ExcelFile("test1" + read_ext, engine=excel_engine)
../excel/test_readers.py:853:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../../io/excel/_base.py:791: in __init__
self._reader = self._engines[engine](self._io)
../../../io/excel/_xlrd.py:21: in __init__
import_optional_dependency("xlrd", extra=err_msg)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
name = 'xlrd', extra = 'Install xlrd >= 1.0.0 for Excel support', raise_on_missing = True, on_version = 'raise'
def import_optional_dependency(
name: str,
extra: str = "",
raise_on_missing: bool = True,
on_version: str = "raise",
):
"""
Import an optional dependency.
By default, if a dependency is missing an ImportError with a nice
message will be raised. If a dependency is present, but too old,
we raise.
Parameters
----------
name : str
The module name. This should be top-level only, so that the
version may be checked.
extra : str
Additional text to include in the ImportError message.
raise_on_missing : bool, default True
Whether to raise if the optional dependency is not found.
When False and the module is not present, None is returned.
on_version : str {'raise', 'warn'}
What to do when a dependency's version is too old.
* raise : Raise an ImportError
* warn : Warn that the version is too old. Returns None
* ignore: Return the module, even if the version is too old.
It's expected that users validate the version locally when
using ``on_version="ignore"`` (see. ``io/html.py``)
Returns
-------
maybe_module : Optional[ModuleType]
The imported module, when found and the version is correct.
None is returned when the package is not found and `raise_on_missing`
is False, or when the package's version is too old and `on_version`
is ``'warn'``.
"""
try:
module = importlib.import_module(name)
except ImportError:
if raise_on_missing:
> raise ImportError(message.format(name=name, extra=extra)) from None
E ImportError: Missing optional dependency 'xlrd'. Install xlrd >= 1.0.0 for Excel support Use pip or conda to install xlrd.
The actual excel reading (interactively) is not affected, so certainly not a blocking issue.