Replies: 7 comments 5 replies
-
I think, in general, it is a bad idea to monkey patch core functionality of the language. Not always, pytest is a good example, but we need a really good reason. Reasons I think this is not desirable:
It is regrettable that:
but I'm not sure the answer is more code and more dependencies. I'm willing to have my mind changed by a compelling counterpoint though! |
Beta Was this translation helpful? Give feedback.
-
For completeness, here is the matplotlib discussion that brought me here: |
Beta Was this translation helpful? Give feedback.
-
To be fair, the import system of Python is confusing even without these kind of patches, especially for submodules. For example:
As |
Beta Was this translation helpful? Give feedback.
-
FYI this idea has been proposed in the "scientific python org" : SPEC0001 Re the dependency issue : The suggested 'lazy-loader' is only one possible solution : we can instead easily provide our own, since the basic idea is quite simple. I agree that providing lazy-loading is sort of "not what Python does" I think there are only a few practical options
|
Beta Was this translation helpful? Give feedback.
-
What if we reverted the change and go back to import iris.cube by default in iris |
Beta Was this translation helpful? Give feedback.
-
See GeoVista for a worked example of using lazy_loader. Would be great to look into this for Iris. |
Beta Was this translation helpful? Give feedback.
-
This recent conversation across on pyvista is kinda relevant ... just cross-referencing for awareness 👍 |
Beta Was this translation helpful? Give feedback.
-
Since Iris v3.1 and #4174, some Iris subpackages/modules that used to be available automatically no longer are and must be imported explicitly. Some users have raised concerns about this (#4683 and various Yammer threads).
I stumbled across this package that attempts to square the circle of convenient namespaces and import performance:
https://github.com/scientific-python/lazy_loader
It seems its authors are keen for this approach to be adopted across the Scientific Python Ecosystem:
https://scientific-python.org/specs/spec-0001/
In our case, it would mean a user could do something like
and
iris.cube
would be imported when it is accessed.I'm not suggesting we should immediately adopt this because
lazy_loader
is a new, two-man project and not [yet?] widely adoptedBut maybe something to have in mind depending how things develop.
Beta Was this translation helpful? Give feedback.
All reactions