-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
Misleading error message when PyTables is not installed #61521
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Replacing these lines: pandas/pandas/compat/_optional.py Lines 151 to 157 in c708e15
with: package_name = INSTALL_MAPPING.get(name, name)
msg = (
f"Missing optional dependency {package_name}. {extra} "
f"Use pip or conda to install package `{name}`."
) and also changing this lines: pandas/pandas/compat/_optional.py Line 73 in c708e15
to: "tables": "PyTables", Produces a much clearer and more helpful error:
|
Take |
Just a heads up that I don't think the fix I suggested will work as-is... the install mapping has the form {"import name" : "PyPI package name"} pandas/pandas/compat/_optional.py Lines 62 to 74 in c708e15
but for PyTables, we do Instead, perhaps the mapping should be modified to include three names, with the import name as a key, and install name and colloquial name as a tuple for its value, e.g.: # A mapping from import name to package name (on PyPI) and colloquial
# name for packages where these names are different.
INSTALL_MAPPING = {
"bs4": ("beautifulsoup4", "Beautiful Soup"),
"bottleneck": ("Bottleneck", "Bottleneck"),
"jinja2": ("Jinja2", "Jinja2"),
"lxml.etree": ("lxml", "lxml"),
"odf": ("odfpy", "odfpy"),
"python_calamine": ("python-calamine", "python-calamine"),
"sqlalchemy": ("SQLAlchemy", "SQLAlchemy"),
"tables": ("tables", "PyTables"),
} And then inside of other_names = INSTALL_MAPPING.get(name)
if other_names:
import_name = name
pypi_name = other_names[0]
colloquial_name = other_names[1]
else:
import_name = name
pypi_name = name
colloquial_name = name
msg = (
f"Missing optional dependency {colloquial_name}. "
f"Unable to import {import_name}. {extra} "
f"Use pip or conda to install package `{pypi_name}`."
) |
PyTables uses |
It seems perhaps the issue is more with the naming conventions adopted by PyTables. I think this is the source of the confusion... and so perhaps it's not reasonable to expect pandas to make sure error messages account for the poor naming choices from third party packages.
The import error in this case is from
To this?
With no mention of the import name To me the confusing part was that the message made no mention of Why not include both the key and value from the mapping dict in the message? That way, both |
I'd be fine with |
+1. This message is much clearer, and I think would resolve this issue. |
I tried reading an hd5 file with the latest pandas and got this import error:
ImportError: Missing optional dependency 'pytables'. Use pip or conda to install pytables.
So I tried
pip install pytables
and got this error:So then I went searching on PyPI and apparently there are no packages named
pytables
: https://pypi.org/search/?q=pytablesI did find the PyTables project on GitHub though, which says that we need to use
pip install tables
to install it. After installingtables
, the hd5 read operation worked.So, we need to install tables, not pytables, which is definitely confusing and not obvious. I think it would be very helpful if the error message indicated this to avoid having to go through the search process above.
The text was updated successfully, but these errors were encountered: