Skip to content
Browse files

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
  • Loading branch information...
1 parent bae849b commit 8719351ed3db3c727c13a43704e7f72358488b52 @minrk committed Oct 20, 2011
Showing with 17 additions and 12 deletions.
  1. +17 −12 IPython/core/magic.py
View
29 IPython/core/magic.py
@@ -862,18 +862,23 @@ def magic_whos(self, parameter_s=''):
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__
+ ndarray_type = None
+ if 'numpy' in sys.modules:
+ try:
+ from numpy import ndarray
+ except ImportError:
+ pass
+ else:
+ ndarray_type = ndarray.__name__
+
+ array_type = None
+ if 'Numeric' in sys.modules:
+ try:
+ from Numeric import ArrayType
+ except ImportError:
+ pass
+ else:
+ array_type = ArrayType.__name__
# Find all variable names and types so we can figure out column sizes
def get_vars(i):

0 comments on commit 8719351

Please sign in to comment.
Something went wrong with that request. Please try again.