Permalink
Browse files

Merge pull request #910 from minrk/pypynumpy

%whos no longer imports numpy unconditionally, and no longer supports Numeric.
The import check explicitly looks for the ndarray object, rather than just numpy itself, which would fail in environments with broken numpy, such as PyPy.

closes gh-904
  • Loading branch information...
minrk committed Oct 25, 2011
2 parents fbd82bd + 9f2252c commit 4c90e86140d2cb82ea1089505354c844ed9ada57
Showing with 10 additions and 14 deletions.
  1. +10 −14 IPython/core/magic.py
View
@@ -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

0 comments on commit 4c90e86

Please sign in to comment.