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
pylab import adjustments #3568
pylab import adjustments #3568
Conversation
I didn't test the magic, but this seems to fix the use from Thanks for adding the flag to the magic. That will be useful for SymPy's example notebooks. |
What was the final decision about warning users about imports from #2664? |
I've added a warning. I'm ambivalent about its desirability. |
Looks fine to me and warning is not too intrusive. |
this changes the meaning of With this change, it will no longer be possible to have the old behavior of having additionally, if this change goes in, we should note it down in |
IMHO you shouldn't do that. As far as I'm concerned, the importing of But +1 regardless for documenting these changes in release notes or somewhere similar. |
the meaning of |
It wasn't a bug - the code and the docs were pretty clear that it was On 9 July 2013 21:26, Paul Ivanov notifications@github.com wrote:
|
Aside from the known use of SymPy, you can check with @jenshnielsen who originally implemented it at #551. SymPy's use doesn't want anything imported (we just want to setup the eventloop). Since the eventloop setup is so important, and really unrelated to imports, I can imagine that that would be a very common use-case. |
It may not have been a bug, but I think it was the wrong decision. I don't think there are many (or any) people who want all the imports except Help string has been updated. |
without the |
But look at it from the point of view of someone like me who just wants to setup the eventloop without importing stuff (preferably without even importing it internally unless it has to, for speed purposes). With a second option, it gets complicated. |
I think there's a fairly simple issue here - there are users who didn't like that we touched their namespace. As a direct result, we added the |
So I had a chance to sleep on this (still sick, so hooray for naps!) and it seems fishy to have a flag to |
I didn't know about |
On Tue, Jul 9, 2013 at 7:58 PM, Aaron Meurer notifications@github.comwrote:
Brian E. Granger |
I just checked, and the behavior and meaning of pylab_import_all hasn't changed since 0.8.4 (actually before that, the changelog notes this change on 2007-03-18)
The additional (unconditional) namespace imports ( # Import numpy as np/pyplot as plt are conventions we're trying to
# somewhat standardize on. Making them available to users by default
# will greatly help this.
exec ("import numpy\n"
"import numpy as np\n"
"import matplotlib\n"
"import matplotlib.pylab as pylab\n"
"try:\n"
" import matplotlib.pyplot as plt\n"
"except ImportError:\n"
" pass\n"
) in user_ns |
@ivanov is right. I reimplemented the pylab_import_all functionality for IPython post 0.11 matching the original implementation. The functionality was lost in the transition to the new config system, all I did was to restore it to match the orignal behaviour. I am split on this behaviour, on one hand it will break existing notebooks and I find it quite logical that a matplotlib |
Would it clarify the code some of we renamed the boolean variable |
You are still thinking of pylab as something that imports stuff, but I want behavior that doesn't import stuff, just sets up the eventloop. Can someone clarify something about the eventloop integration. Do numpy and/or matplotlib have to be imported for that to be set up? |
It does all kinds of pylab stuff - setting up the inline backend, selecting the matplotlib backend, activating figure formatters. Imports are only one piece of what pylab does, and it really should be optional. I didn't realize the import_all switch had existed prior to the addition of the config value, thanks. I had never heard of anyone using it before the config value, but plenty of complaints about not being able to set up matplotlib without affecting the namespace. |
OK, so there's no hope of making it faster by not importing things. |
No, if speed is your concern, this has no effect at all - everything being added to is already imported, just not in the interactive namespace. |
Just chatted with @fperez, and here's an alternate proposal:
I'm pretty sure a proposal very similar to this has been made before, but nobody has actually implemented it. |
What about the internal API? I like this idea, though it does make |
Sorry, when I say "internal API", I mean "Python API". I care about how SymPy will call out to this from its |
You would call |
and no messages displayed |
+1. It's probably too late to integrate this API into SymPy 0.7.3 (I plan to do the final release either tomorrow or Sunday; yay we finally get a release out before you guys), but it's not big deal, because I think we are finally approaching a point with SymPy where we can release on a regular basis. |
magic_gui_arg = magic_arguments.argument( | ||
'gui', nargs='?', | ||
help="""Name of the matplotlib backend to use | ||
('qt', 'wx', 'gtk', 'osx', 'tk', 'inline', 'auto'). |
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.
not worth holding up this PR, but I tend to prefer interpolating strings like this from some programmatically available list (so if we change the list of backends, we don't have to update such string in a whole bunch of different places), Something like from IPython.core.pylabtools import backends
and then interpolate in sorted(backends.keys())
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.
ok, sent you a PR that includes a change for this
I sent you a PR that fixes two failing tests, but there's still one more failing for the inprocesss kernel:
|
fix 2 failing tests and add programmatic support for backend
@ivanov thanks, merged your PR, and the inprocess failure should be fixed as well. |
welcome message has changed
alright, status ok, thanks Min, merging! |
new %matplotlib magic, quieter %pylab magic %matplotlib is a magic which sets up integration but does no imports %pylab now is now as verbose about announcing itself.
So now, we should tell peolple to use |
that's right, Matthias, @minrk and I were also talking about eventually adding an %import magic that would allow other packages to effectively set up some form of integration with ipython, but with a minimal amount of work, and in a manner that'd be natural for the user to also expect an imported package to be there afterwards. so |
What is the API call? |
@asmeurer the idea (which came from @fperez) is to generalize |
Actually, I mean what is the API call associated with %matplotlib. But I see now from the commit messages that it's just |
Right, sorry - yes, the various |
Wait, so what is %gui then? |
|
Ah, so there is a strict hierarchy of magics |
yes - though technically only one magic is ever actually called, but multiple |
I just wanted to be sure that my hierarchy is right here.
|
exactly right, yes. |
Now that ipython#3568 is merged, we should steer folks in that direction
new %matplotlib magic, quieter %pylab magic %matplotlib is a magic which sets up integration but does no imports %pylab now is now as verbose about announcing itself.
Now that ipython#3568 is merged, we should steer folks in that direction
%pylab --no-import
import_pylab
to import nothing when import_all is Falseit's all or nothing now, not all or some. Now
pylab_import_all=False
should mean that no symbols are added to the user namespace.This also removes
figsize
from the pyplot namespace, which was weird and confusing.closes #2630
closes #2664
closes #3436