-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Delay import #17710
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
Delay import #17710
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
86050cd
Delay matplotlib import
TomAugspurger be3d13e
delay pytest
TomAugspurger cd2226c
Delay excel, probably broken
TomAugspurger 95d96fc
Matplotlib cleanup
TomAugspurger bede1f9
excel configuration
TomAugspurger a1a15bb
PERF: delay numexpr
TomAugspurger 028bb8a
fixup! Matplotlib cleanup
TomAugspurger 85f8baa
PERF: delay import of py.path, Pathlib
TomAugspurger 748ea2d
Add a script to test imports
TomAugspurger 52295b8
CI: Check for accidental imports
TomAugspurger 067b561
whatsnew
TomAugspurger b9f6a14
Added release note
TomAugspurger 9bbd9c6
Fix script call
TomAugspurger 9d0f74a
pep8
TomAugspurger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
""" | ||
Check that certain modules are not loaded by `import pandas` | ||
""" | ||
import sys | ||
|
||
blacklist = { | ||
'bs4', | ||
'html5lib', | ||
'ipython', | ||
'jinja2' | ||
'lxml', | ||
'matplotlib', | ||
'numexpr', | ||
'openpyxl', | ||
'py', | ||
'pytest', | ||
's3fs', | ||
'scipy', | ||
'tables', | ||
'xlrd', | ||
'xlsxwriter', | ||
'xlwt', | ||
} | ||
|
||
|
||
def main(): | ||
import pandas # noqa | ||
|
||
modules = set(x.split('.')[0] for x in sys.modules) | ||
imported = modules & blacklist | ||
if modules & blacklist: | ||
sys.exit("Imported {}".format(imported)) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +0,0 @@ | ||
|
||
import warnings | ||
from distutils.version import LooseVersion | ||
|
||
_NUMEXPR_INSTALLED = False | ||
_MIN_NUMEXPR_VERSION = "2.4.6" | ||
|
||
try: | ||
import numexpr as ne | ||
ver = ne.__version__ | ||
_NUMEXPR_INSTALLED = ver >= LooseVersion(_MIN_NUMEXPR_VERSION) | ||
|
||
if not _NUMEXPR_INSTALLED: | ||
warnings.warn( | ||
"The installed version of numexpr {ver} is not supported " | ||
"in pandas and will be not be used\nThe minimum supported " | ||
"version is {min_ver}\n".format( | ||
ver=ver, min_ver=_MIN_NUMEXPR_VERSION), UserWarning) | ||
|
||
except ImportError: # pragma: no cover | ||
pass | ||
|
||
__all__ = ['_NUMEXPR_INSTALLED'] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import warnings | ||
from distutils.version import LooseVersion | ||
|
||
_NUMEXPR_INSTALLED = False | ||
_MIN_NUMEXPR_VERSION = "2.4.6" | ||
|
||
try: | ||
import numexpr as ne | ||
ver = ne.__version__ | ||
_NUMEXPR_INSTALLED = ver >= LooseVersion(_MIN_NUMEXPR_VERSION) | ||
|
||
if not _NUMEXPR_INSTALLED: | ||
warnings.warn( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we do the same type of thing with bottleneck |
||
"The installed version of numexpr {ver} is not supported " | ||
"in pandas and will be not be used\nThe minimum supported " | ||
"version is {min_ver}\n".format( | ||
ver=ver, min_ver=_MIN_NUMEXPR_VERSION), UserWarning) | ||
|
||
except ImportError: # pragma: no cover | ||
pass | ||
|
||
__all__ = ['_NUMEXPR_INSTALLED'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,6 @@ | |
|
||
from pandas import compat | ||
from pandas.util._decorators import Appender | ||
import pandas.core.computation.expressions as expressions | ||
|
||
from pandas.compat import bind_method | ||
import pandas.core.missing as missing | ||
|
@@ -668,8 +667,9 @@ def _arith_method_SERIES(op, name, str_rep, fill_zeros=None, default_axis=None, | |
Wrapper function for Series arithmetic operations, to avoid | ||
code duplication. | ||
""" | ||
|
||
def na_op(x, y): | ||
import pandas.core.computation.expressions as expressions | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if these imports become an issue i can do a global check (like u do with matplotlib) |
||
|
||
try: | ||
result = expressions.evaluate(op, str_rep, x, y, | ||
raise_on_error=True, **eval_kwargs) | ||
|
@@ -1193,6 +1193,8 @@ def to_series(right): | |
def _arith_method_FRAME(op, name, str_rep=None, default_axis='columns', | ||
fill_zeros=None, **eval_kwargs): | ||
def na_op(x, y): | ||
import pandas.core.computation.expressions as expressions | ||
|
||
try: | ||
result = expressions.evaluate(op, str_rep, x, y, | ||
raise_on_error=True, **eval_kwargs) | ||
|
@@ -1349,6 +1351,8 @@ def _arith_method_PANEL(op, name, str_rep=None, fill_zeros=None, | |
# copied from Series na_op above, but without unnecessary branch for | ||
# non-scalar | ||
def na_op(x, y): | ||
import pandas.core.computation.expressions as expressions | ||
|
||
try: | ||
result = expressions.evaluate(op, str_rep, x, y, | ||
raise_on_error=True, **eval_kwargs) | ||
|
@@ -1378,6 +1382,8 @@ def f(self, other): | |
|
||
def _comp_method_PANEL(op, name, str_rep=None, masker=False): | ||
def na_op(x, y): | ||
import pandas.core.computation.expressions as expressions | ||
|
||
try: | ||
result = expressions.evaluate(op, str_rep, x, y, | ||
raise_on_error=True) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe make a checking_imports.sh just to make style similar to existing