Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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...
commit 8719351ed3db3c727c13a43704e7f72358488b52 1 parent bae849b
Min RK authored

Showing 1 changed file with 17 additions and 12 deletions. Show diff stats Hide diff stats

  1. +17 12 IPython/core/magic.py
29 IPython/core/magic.py
@@ -862,18 +862,23 @@ def magic_whos(self, parameter_s=''):
862 862 seq_types = ['dict', 'list', 'tuple']
863 863
864 864 # for numpy/Numeric arrays, display summary info
865   - try:
866   - import numpy
867   - except ImportError:
868   - ndarray_type = None
869   - else:
870   - ndarray_type = numpy.ndarray.__name__
871   - try:
872   - import Numeric
873   - except ImportError:
874   - array_type = None
875   - else:
876   - array_type = Numeric.ArrayType.__name__
  865 + ndarray_type = None
  866 + if 'numpy' in sys.modules:
  867 + try:
  868 + from numpy import ndarray
  869 + except ImportError:
  870 + pass
  871 + else:
  872 + ndarray_type = ndarray.__name__
  873 +
  874 + array_type = None
  875 + if 'Numeric' in sys.modules:
  876 + try:
  877 + from Numeric import ArrayType
  878 + except ImportError:
  879 + pass
  880 + else:
  881 + array_type = ArrayType.__name__
877 882
878 883 # Find all variable names and types so we can figure out column sizes
879 884 def get_vars(i):

0 comments on commit 8719351

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