From 8719351ed3db3c727c13a43704e7f72358488b52 2011-10-20 18:59:10 From: MinRK Date: 2011-10-20 18:59:10 Subject: [PATCH] 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 --- diff --git a/IPython/core/magic.py b/IPython/core/magic.py index 07a4ee4..17ada3b 100644 --- a/IPython/core/magic.py +++ b/IPython/core/magic.py @@ -862,18 +862,23 @@ Currently the magic system has the following functions:\n""" 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):