diff options
Diffstat (limited to 'numpy/__init__.py')
-rw-r--r-- | numpy/__init__.py | 55 |
1 files changed, 43 insertions, 12 deletions
diff --git a/numpy/__init__.py b/numpy/__init__.py index fef8245de..2d3423c56 100644 --- a/numpy/__init__.py +++ b/numpy/__init__.py @@ -104,8 +104,6 @@ available as array methods, i.e. ``x = np.array([1,2,3]); x.sort()``. Exceptions to this rule are documented. """ -from __future__ import division, absolute_import, print_function - import sys import warnings @@ -143,7 +141,8 @@ else: from .core import * from . import compat from . import lib - # FIXME: why have numpy.lib if everything is imported here?? + # NOTE: to be revisited following future namespace cleanup. + # See gh-14454 and gh-15672 for discussion. from .lib import * from . import linalg @@ -154,28 +153,28 @@ else: from . import ma from . import matrixlib as _mat from .matrixlib import * - from .compat import long # Make these accessible from numpy name-space # but not imported in from numpy import * - if sys.version_info[0] >= 3: - from builtins import bool, int, float, complex, object, str - unicode = str - else: - from __builtin__ import bool, int, float, complex, object, unicode, str + # TODO[gh-6103]: Deprecate these + from builtins import bool, int, float, complex, object, str + from .compat import long, unicode from .core import round, abs, max, min # now that numpy modules are imported, can initialize limits core.getlimits._register_known_types() - __all__.extend(['bool', 'int', 'float', 'complex', 'object', 'unicode', - 'str']) __all__.extend(['__version__', 'show_config']) __all__.extend(core.__all__) __all__.extend(_mat.__all__) __all__.extend(lib.__all__) __all__.extend(['linalg', 'fft', 'random', 'ctypeslib', 'ma']) + # These are added by `from .core import *` and `core.__all__`, but we + # overwrite them above with builtins we do _not_ want to export. + __all__.remove('long') + __all__.remove('unicode') + # Remove things that are in the numpy.lib but not in the numpy namespace # Note that there is a test (numpy/tests/test_public_api.py:test_numpy_namespace) # that prevents adding more things to the main namespace by accident. @@ -216,7 +215,7 @@ else: "{!r}".format(__name__, attr)) def __dir__(): - return __all__ + ['Tester', 'testing'] + return list(globals().keys() | {'Tester', 'testing'}) else: # We don't actually use this ourselves anymore, but I'm not 100% sure that @@ -254,3 +253,35 @@ else: _sanity_check() del _sanity_check + + def _mac_os_check(): + """ + Quick Sanity check for Mac OS look for accelerate build bugs. + Testing numpy polyfit calls init_dgelsd(LAPACK) + """ + try: + c = array([3., 2., 1.]) + x = linspace(0, 2, 5) + y = polyval(c, x) + _ = polyfit(x, y, 2, cov=True) + except ValueError: + pass + + import sys + if sys.platform == "darwin": + with warnings.catch_warnings(record=True) as w: + _mac_os_check() + # Throw runtime error, if the test failed Check for warning and error_message + error_message = "" + if len(w) > 0: + error_message = "{}: {}".format(w[-1].category.__name__, str(w[-1].message)) + msg = ( + "Polyfit sanity test emitted a warning, most likely due " + "to using a buggy Accelerate backend. " + "If you compiled yourself, " + "see site.cfg.example for information. " + "Otherwise report this to the vendor " + "that provided NumPy.\n{}\n".format( + error_message)) + raise RuntimeError(msg) + del _mac_os_check |