-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Lazy Imports #7179
Lazy Imports #7179
Conversation
Very nice @headtr1ck ! |
Not as much of an improvement as I thought, but shaving off another 20ms. I can see if I can bring it down even further... |
Do you think there's a risk something gets added back by mistake? A galaxy brain idea is to have a lint in pre-commit which looks for |
The simplest solution would be to add a simple unit test that checks that blacklisted packets are not in For import timings we have asv, but that is not run so often. |
Now I have made every module lazy that is not too much work, this includes: The only remaining large import is |
Seems like it is but a good idea to mess with sys.modules in pytest. Anyone got an idea how to solve that? Edit: solved :) |
I managed to get Someone else has to tackle this, I am not too familiar with this... This got the import time quite low. I am happy with this now :) |
It seems that |
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.
Very nice! I've felt the long import times recently and this will help greatly!
Maybe next step in a future PR is to try making pandas lazy as well? I don't think it's used as much as the top import in every file makes it out to be.
Thanks @headtr1ck great PR! |
Exciting improvements on usability for the next version! |
FYI I'm getting this error when trying to update the version in pyodide: https://app.circleci.com/pipelines/github/pyodide/pyodide/5016/workflows/e2cc0865-a91d-4cdb-8dbc-dfaeeb522c5f/jobs/60731 JavascriptException message: Traceback (most recent call last):
File "/lib/python3.10/asyncio/futures.py", line 201, in result
raise self._exception
File "/lib/python3.10/asyncio/tasks.py", line 232, in __step
result = coro.send(None)
File "/lib/python3.10/_pyodide/_base.py", line 531, in eval_code_async
await CodeRunner(
File "/lib/python3.10/_pyodide/_base.py", line 357, in run_async
coroutine = eval(self.code, globals, locals)
File "<exec>", line 1, in <module>
File "/lib/python3.10/site-packages/xarray/__init__.py", line 1, in <module>
from . import testing, tutorial
File "/lib/python3.10/site-packages/xarray/tutorial.py", line 17, in <module>
from .backends.api import open_dataset as _open_dataset
File "/lib/python3.10/site-packages/xarray/backends/__init__.py", line 16, in <module>
from .scipy_ import ScipyBackendEntrypoint, ScipyDataStore
File "/lib/python3.10/site-packages/xarray/backends/scipy_.py", line 239, in <module>
class ScipyBackendEntrypoint(BackendEntrypoint):
File "/lib/python3.10/site-packages/xarray/backends/scipy_.py", line 260, in ScipyBackendEntrypoint
available = module_available("scipy")
File "/lib/python3.10/site-packages/xarray/core/utils.py", line 1009, in module_available
return importlib.util.find_spec(module) is not None
File "/lib/python3.10/importlib/util.py", line 103, in find_spec
return _find_spec(fullname, parent_path)
File "/lib/python3.10/_pyodide/_importhook.py", line 226, in find_spec
raise ModuleNotFoundError(
ModuleNotFoundError: The module 'scipy' is included in the Pyodide distribution, but it is not installed. You can install it by calling: await micropip.install("scipy") in Python or await pyodide.loadPackage("scipy") in JavaScript. See https://pyodide.org/en/stable/usage/loading-packages.html for more details. this seems like a bug in importlib |
I don't think this is a bug in importlib but rather pyodide. They seem to add a hook to importlib (which is allowed, but probably causing this issue?) Edit: The error message from pyodide seems more like this is intentional? Is scipy really installed correctly? |
Turns out it is a pyodide bug with how they hook in to importlib |
Tests addedwhats-new.rst
New functions/methods are listed inapi.rst