-
Notifications
You must be signed in to change notification settings - Fork 271
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
ENH: Only call find_spec sometimes #4640
Conversation
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.
good catch !
if display_array and find_spec("ipywidgets") is not None: | ||
self.display_array = True | ||
else: | ||
self.display_array = False |
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.
I have a small preference for the one-liner form, but it's not crucial (I've checked that it is black-compliant)
if display_array and find_spec("ipywidgets") is not None: | |
self.display_array = True | |
else: | |
self.display_array = False | |
self.display_array = display_array and find_spec("ipywidgets") is not None |
Note that this isn't 100% true: it is possible to install a package at runtime using |
Yeah, I know it's not strictly true, but it's true enough. We shouldn't bother catching it. |
agreed |
for a bit of extra context: we found that this |
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.
Oops, didn't actually hit approve with my last comment :)
Moving this to 4.2.2 upon @matthewturk's request |
In some cases, particularly when instantiating lots of child masks, the way the
MutableAttribute
object is set up could lead tofind_spec
being called inside some tight loops.But, the results of
find_spec
shouldn't change during the course of one interpreter's existence. So we can move the checks to the outside of the__get__
call, which reduces costs of grid indexing considerable in some cases.