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

ipython notebook --pylab=inline replaces built-in any() #2598

Closed
invisibleroads opened this Issue Nov 17, 2012 · 6 comments

Comments

Projects
None yet
4 participants
@invisibleroads
Contributor

invisibleroads commented Nov 17, 2012

Running "ipython notebook --pylab=inline" replaces the built-in any() with its numpy counterpart.

Expected
<function any>

Actual
<function numpy.core.fromnumeric.any>

@invisibleroads

This comment has been minimized.

Contributor

invisibleroads commented Nov 17, 2012

For the meantime, using the __builtin__ module works.

from __builtin__ import any

@Carreau

This comment has been minimized.

Member

Carreau commented Nov 17, 2012

Yes, this is expected behavior from --pylab

IPython --help-all :

--pylab=<CaselessStrEnum> (InteractiveShellApp.pylab)
    Default: None
    Choices: ['tk', 'qt', 'wx', 'gtk', 'osx', 'inline', 'auto']
    Pre-load matplotlib and numpy for interactive use, selecting a particular
    matplotlib backend and loop integration.

--TerminalIPythonApp.pylab_import_all=<Bool>
    Default: True
    If true, an 'import *' is done from numpy and pylab, when using pylab
@Carreau

This comment has been minimized.

Member

Carreau commented Nov 17, 2012

This is of course configurable in your profile.
Closing.

@Carreau Carreau closed this Nov 17, 2012

@invisibleroads

This comment has been minimized.

Contributor

invisibleroads commented Nov 17, 2012

Cool, thanks.

@takluyver

This comment has been minimized.

Member

takluyver commented Nov 17, 2012

This is a bit annoying, because numpy's any doesn't work on lists. I suspect the appearance in pylab might predate the builtin any, which was introduced with Python 2.5.

I wonder if it's worth defining a compatibility any, that calls numpy.any for arrays, and the builtin any otherwise. But perhaps that would just be more confusing.

@invisibleroads

This comment has been minimized.

Contributor

invisibleroads commented Nov 17, 2012

Well, I was just trying to test whether any() called on a generator stops early and found that it does, using the console IPython. When I tried to include the code example in a tutorial, the numpy.any() kept returning a generator instead of True or False.

from __builtin__ import any

def walk_numbers():
    print 'start'
    for i in xrange(10):
        yield i
    print 'end'

# The built-in any() stops as soon as the condition is met
print any(x > 5 for x in walk_numbers())
print
print any(x > 10 for x in walk_numbers())

@minrk minrk added this to the no action milestone Mar 26, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment