Conversation
18e0685 to
6c36fba
Compare
6c36fba to
54182f0
Compare
|
This is interesting. If I understand right, the idea is that once scipy/numpy/matplotlib make it so importing sub packages happens automagically upon attr lookup, we will remove the commented import lines. I like the idea that a single import of scipy allows you to be able to use e.g. scipy.sparse without having to import that sub package explicitly. Could we do the same thing? Instead of having to import approximations separately, let's try to make it so nx.approximations loads the sub package. If we work the kinks out for that, we might learn enough to try to make it work for scipy, numpy, etc. But that's another PR. |
I definitely agree. I haven't looked too closely at the |
|
@stefanv is looking into lazy imports and said he thinks it should be doable. This is for another PR as well, but I noticed some of our examples were doing this instead of this I fixed them in #4403. But we should clean up our |
|
I have a working prototype. https://gist.github.com/stefanv/fde776cef7464b4e2cc0721bd37d51f4 Using this, I had to modify scikit-image's main from .lazy import require
def __getattr__(name):
return require(f'skimage.{name}')Then, when you do: it lazy loads, and works! The only problem I've noticed is that it makes IPython's auto-completer very angry, but I suspect we can work with that team to address it. |
d86484b to
cb08f7d
Compare
rossbar
left a comment
There was a problem hiding this comment.
A couple questions/comments but overall looks good.
I generally agree that the import style proposed here is an improvement, even more so with lazy importing.
Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
cb08f7d to
5777f0a
Compare
* Standardize pytest imports * Standardize numpy/scipy imports * Document import style * Fix * More * Fix matplotlib imports * Revert changes to tests * Motivate import policy Co-authored-by: Ross Barnowski <rossbar@berkeley.edu> * Fix missed imports * Standard np.testing use Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
Closes #4277 and makes searching for
np,sp,linalg, etc. more helpful.If scipy implements lazy loading a la https://snarky.ca/lazy-importing-in-python-3-7/ (maybe one of us should contribute it), then we can just remove all the lines like
similarly for matplotlib and lines like