Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Make import checks more explicit in %whos #910

Merged
merged 2 commits into from

3 participants

@minrk
Owner

Since PyPy has a fake numpy, checking for 'import numpy' is insufficient

only check if numpy/numeric in use, to prevent unnecessary imports

%precision has a similar issue, but I'm actually inclined to let it raise (it doesn't crash, or anything, just shows that numpy is not really numpy). %whos is more important, and was entirely broken on PyPy.

closes #904

@minrk minrk Make import checks more explicit in %whos
Since PyPy has a fake numpy, checking for 'numpy' is insufficient

only check if numpy/numeric in use, to prevent unnecessary imports

closes gh-904
8719351
@takluyver
Owner

Looks sensible. Do we actually still need to check for numeric? It's no longer even in Ubuntu/Debian repos, and the last binary installer is for Python 2.4.

@minrk
Owner

lol, good point. I think it's perfectly fine to drop support for pretty-printed Numeric arrays in %whos.

@minrk
Owner

Numeric removed

IPython/core/magic.py
@@ -918,7 +914,7 @@ Currently the magic system has the following functions:\n"""
print vformat.format(vname, vtype, varwidth=varwidth, typewidth=typewidth),
if vtype in seq_types:
print "n="+str(len(var))
- elif vtype in [array_type,ndarray_type]:
+ elif vtype in [ndarray_type]:
@takluyver Owner

This doesn't really need the in test now.

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

Other than that, it looks fine (I assume you've run it on PyPy)

@minrk
Owner

comment addressed.

And yes, I have run it on pypy, and also in CPython with a dummy numpy.py that prevents numpy from making any sense.

@fperez
Owner

+1 from me. Guys, I'm really offline starting tomorrow, so go ahead without me on this one...

@minrk minrk merged commit 4c90e86 into from
@ellisonbg ellisonbg referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 20, 2011
  1. @minrk

    Make import checks more explicit in %whos

    minrk authored
    Since PyPy has a fake numpy, checking for 'numpy' is insufficient
    
    only check if numpy/numeric in use, to prevent unnecessary imports
    
    closes gh-904
  2. @minrk
This page is out of date. Refresh to see the latest.
Showing with 10 additions and 14 deletions.
  1. +10 −14 IPython/core/magic.py
View
24 IPython/core/magic.py
@@ -861,19 +861,15 @@ def magic_whos(self, parameter_s=''):
# for these types, show len() instead of data:
seq_types = ['dict', 'list', 'tuple']
- # for numpy/Numeric arrays, display summary info
- try:
- import numpy
- except ImportError:
- ndarray_type = None
- else:
- ndarray_type = numpy.ndarray.__name__
- try:
- import Numeric
- except ImportError:
- array_type = None
- else:
- array_type = Numeric.ArrayType.__name__
+ # for numpy arrays, display summary info
+ ndarray_type = None
+ if 'numpy' in sys.modules:
+ try:
+ from numpy import ndarray
+ except ImportError:
+ pass
+ else:
+ ndarray_type = ndarray.__name__
# Find all variable names and types so we can figure out column sizes
def get_vars(i):
@@ -918,7 +914,7 @@ def type_name(v):
print vformat.format(vname, vtype, varwidth=varwidth, typewidth=typewidth),
if vtype in seq_types:
print "n="+str(len(var))
- elif vtype in [array_type,ndarray_type]:
+ elif vtype == ndarray_type:
vshape = str(var.shape).replace(',','').replace(' ','x')[1:-1]
if vtype==ndarray_type:
# numpy
Something went wrong with that request. Please try again.