Skip to content

improve error message when importing pandas from source directory #9626

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

Merged
merged 1 commit into from
May 4, 2015

Conversation

mortada
Copy link
Contributor

@mortada mortada commented Mar 10, 2015

Currently if one imports from the source directory without building the C extension the error message is not very helpful:
ImportError: cannot import name 'hashtable'

I see a few previous PRs (#3827, #3821) that tried to address this but somehow this is still the behavior on master.

With this PR the error message would be a lot more informative:

ImportError: C extension: 'hashtable' not built. If you want to import pandas from the source directory, you may need to run 'python setup.py build_ext --inplace' to build the C extensions first.

@jreback jreback added the Build Library building on various platforms label Mar 13, 2015
@jreback jreback added this to the 0.16.1 milestone Mar 13, 2015
@mortada
Copy link
Contributor Author

mortada commented Apr 12, 2015

@jreback @cpcloud please take a look

raise
from pandas import hashtable, tslib, lib
except ImportError as e: # pragma: no cover
module = str(e).lstrip('cannot import name ') # hack but overkill to use re
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, is it necessary to print the exception? I assume the interpreter will just quit in any event, not sure why was done that way previously. any thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you mean the part about finding out which module causes the ImportError, yes it's not really necessary. But I suppose it was done to make the error message even more specific, i.e. "can't import hashtable, you need to build C extensions" vs "you need to build C extensions"

both would be much better than the current error that says "can't import hashtable" http://stackoverflow.com/questions/14422976/importing-pandas-shows-importerror-cannot-import-name-hashtable

@jreback
Copy link
Contributor

jreback commented May 4, 2015

looks ok to me. @shoyer @jorisvandenbossche @cpcloud
?

@shoyer
Copy link
Member

shoyer commented May 4, 2015

Indeed, looks good to me

jreback added a commit that referenced this pull request May 4, 2015
improve error message when importing pandas from source directory
@jreback jreback merged commit 2cb7414 into pandas-dev:master May 4, 2015
@jreback
Copy link
Contributor

jreback commented May 4, 2015

@mortada thanks!

@mortada mortada deleted the build_c_ext_msg branch May 5, 2015 00:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Build Library building on various platforms
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants