-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Shouldn't the try: __import__ in __init__ re-raise original exception? #23868
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
I'm -1 here as I think this is somewhat nuanced. At the end of the day pytz wasn't fully installed, hence the original error so it's not as if pandas is misleading in that regards. |
I actually wouldn't be too opposed to clarifying this. Would it be so bad to print out all relevant error messages related to each dependency that failed? |
A +1 for this. I do think Pandas is being misleading in this case - I've just spend a good ten minutes trying to figure out why Pandas thinks Numpy isn't installed when I don't see any particular advantage to what Pandas is doing - why not just allow the underlying ImportError to be raised, whether it's the requirement itself missing or some dependency of that, like just about every other package? Turning an ImportError into a potentially less informative ImportError doesn't seem to be very useful. If you really, really want to have the little message that can give a single message saying that all three of numpy, pytz, and dateutil missing, I'd be tempted to go with:
|
We're python 3 only now. All we need to do is
and the full traceback is printed. Are you interested in working on it @DanielFEvans? |
I'm not sure of an easy way to test this. I suspect the current behavior is untested. |
Is there any need to raise a separate import error - i.e. what would Pandas add that isn't already there? If there's a default ImportError that already says that it couldn't find (This is different from some other cases further down in I'd be happy to give this one a go - seems like a fairly simple one to start with! |
Ah, sorry, I misunderstood the issue. The idea is to raise a single error message with all of the import errors, so #23868 (comment) won't quite work. I think the simplest thing is to include the original exception in the |
Problem description
It is confusing when
import pandas
raises a message like:Where actually the true error is not in
pytz
, but in a missing library required bypytz
:As you can see, I happen to have a file called
bisect.py
in the same folder where I'm trying toimport pandas
, but the error message raised bypandas
doesn't reflect that. It was a silly error after all, but It gave me a headache to sort that out.Tracking back the source of it, in
pandas/__init__.py
, note that the original errore
is not used afterexcept ImportError as e
. I think it should.Expected Output
raise ImportError(...)
should mention the errore
raised by__import__(dependency)
Question also asked in SO:
https://stackoverflow.com/questions/53445555/shouldnt-the-try-import-in-init-re-raise-original-exception
The text was updated successfully, but these errors were encountered: