[Python-modules-commits] [python-numpy] 01/12: Import python-numpy_1.11.2~rc1.orig.tar.gz

Sandro Tosi morph at moszumanska.debian.org
Fri Sep 23 19:35:56 UTC 2016


This is an automated email from the git hooks/post-receive script.

morph pushed a commit to branch master
in repository python-numpy.

commit b7041f19a8ab3b1464d7c600715be390138a30de
Author: Sandro Tosi <morph at debian.org>
Date:   Fri Sep 23 14:04:54 2016 +0100

    Import python-numpy_1.11.2~rc1.orig.tar.gz
---
 PKG-INFO                                      |   2 +-
 doc/release/1.11.2-notes.rst                  |  39 ++
 doc/source/release.rst                        |   1 +
 numpy/__init__.py                             |  57 +--
 numpy/_globals.py                             |  62 +++
 numpy/_import_tools.py                        |   5 +-
 numpy/compat/py3k.py                          |  60 ++-
 numpy/core/code_generators/generate_umath.py  |   1 +
 numpy/core/fromnumeric.py                     | 195 ++++++---
 numpy/core/setup.py                           |  13 +-
 numpy/core/src/multiarray/ctors.c             |  50 +--
 numpy/core/src/multiarray/ctors.h             |   2 +-
 numpy/core/src/multiarray/nditer_api.c        |   2 +-
 numpy/core/src/multiarray/shape.c             |   6 +-
 numpy/core/src/npymath/npy_math_complex.c.src |   9 +-
 numpy/core/src/npysort/quicksort.c.src        |  12 +-
 numpy/core/src/private/templ_common.h.src     |   9 +-
 numpy/core/src/umath/scalarmath.c.src         |   5 +-
 numpy/core/tests/test_multiarray.py           |  47 ++-
 numpy/core/tests/test_nditer.py               |  16 +
 numpy/core/tests/test_numeric.py              |  12 +
 numpy/core/tests/test_ufunc.py                |  21 +
 numpy/distutils/ccompiler.py                  |   2 +-
 numpy/distutils/command/config.py             |  45 +++
 numpy/distutils/extension.py                  |  63 +--
 numpy/distutils/misc_util.py                  |  12 +-
 numpy/distutils/msvc9compiler.py              |  62 ++-
 numpy/distutils/msvccompiler.py               |  60 ++-
 numpy/distutils/system_info.py                |  22 +-
 numpy/f2py/__init__.py                        |  27 +-
 numpy/lib/nanfunctions.py                     | 145 +++++--
 numpy/linalg/tests/test_linalg.py             |   4 +-
 numpy/ma/core.py                              | 543 +++++++++++++-------------
 numpy/ma/extras.py                            | 179 ++++-----
 numpy/ma/tests/test_core.py                   | 105 ++++-
 numpy/ma/tests/test_extras.py                 |  83 +++-
 numpy/testing/utils.py                        |  15 +-
 numpy/tests/test_reloading.py                 |  34 ++
 numpy/version.py                              |   8 +-
 setup.py                                      |   9 +-
 40 files changed, 1351 insertions(+), 693 deletions(-)

diff --git a/PKG-INFO b/PKG-INFO
index 90c3fc0..ff4d3a0 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: numpy
-Version: 1.11.1
+Version: 1.11.2rc1
 Summary: NumPy: array processing for numbers, strings, records, and objects.
 Home-page: http://www.numpy.org
 Author: NumPy Developers
diff --git a/doc/release/1.11.2-notes.rst b/doc/release/1.11.2-notes.rst
new file mode 100644
index 0000000..f57afb7
--- /dev/null
+++ b/doc/release/1.11.2-notes.rst
@@ -0,0 +1,39 @@
+NumPy 1.11.2 Release Notes
+**************************
+
+Numpy 1.11.2 supports Python 2.6 - 2.7 and 3.2 - 3.5. It fixes bugs and
+regressions found in Numpy 1.11.1 and includes several build related
+improvements. Wheels for Linux, Windows, and OS X can be found on PyPI.
+
+Pull Requests Merged
+====================
+
+Fixes overridden by later merges and release notes updates are omitted.
+
+- #7736 BUG: Many functions silently drop 'keepdims' kwarg.
+- #7738 ENH: Add extra kwargs and update doc of many MA methods.
+- #7778 DOC: Update Numpy 1.11.1 release notes.
+- #7793 BUG: MaskedArray.count treats negative axes incorrectly.
+- #7816 BUG: Fix array too big error for wide dtypes.
+- #7821 BUG: Make sure npy_mul_with_overflow_<type> detects overflow.
+- #7824 MAINT: Allocate fewer bytes for empty arrays.
+- #7847 MAINT,DOC: Fix some imp module uses and update f2py.compile docstring.
+- #7849 MAINT: Fix remaining uses of deprecated Python imp module.
+- #7851 BLD: Fix ATLAS version detection.
+- #7896 BUG: Construct ma.array from np.array which contains padding.
+- #7904 BUG: Fix float16 type not being called due to wrong ordering.
+- #7917 BUG: Production install of numpy should not require nose.
+- #7919 BLD: Fixed MKL detection for recent versions of this library.
+- #7920 BUG: Fix for issue #7835 (ma.median of 1d).
+- #7932 BUG: Monkey-patch _msvccompile.gen_lib_option like other compilers.
+- #7939 BUG: Check for HAVE_LDOUBLE_DOUBLE_DOUBLE_LE in npy_math_complex.
+- #7953 BUG: Guard against buggy comparisons in generic quicksort.
+- #7954 BUG: Use keyword arguments to initialize Extension base class.
+- #7955 BUG: Make sure numpy globals keep identity after reload.
+- #7972 BUG: MSVCCompiler grows 'lib' & 'include' env strings exponentially.
+- #8005 BLD: Remove __NUMPY_SETUP__ from builtins at end of setup.py.
+- #8010 MAINT: Remove leftover imp module imports.
+- #8020 BUG: Fix return of np.ma.count if keepdims is True and axis is None.
+- #8024 BUG: Fix numpy.ma.median.
+- #8031 BUG: Fix np.ma.median with only one non-masked value.
+- #8044 BUG: Fix bug in NpyIter buffering with discontinuous arrays.
diff --git a/doc/source/release.rst b/doc/source/release.rst
index c6f9ab5..6b11853 100644
--- a/doc/source/release.rst
+++ b/doc/source/release.rst
@@ -2,6 +2,7 @@
 Release Notes
 *************
 
+.. include:: ../release/1.11.2-notes.rst
 .. include:: ../release/1.11.1-notes.rst
 .. include:: ../release/1.11.0-notes.rst
 .. include:: ../release/1.10.4-notes.rst
diff --git a/numpy/__init__.py b/numpy/__init__.py
index 0fcd509..6220269 100644
--- a/numpy/__init__.py
+++ b/numpy/__init__.py
@@ -107,46 +107,10 @@ Exceptions to this rule are documented.
 from __future__ import division, absolute_import, print_function
 
 import sys
+import warnings
 
-
-class ModuleDeprecationWarning(DeprecationWarning):
-    """Module deprecation warning.
-
-    The nose tester turns ordinary Deprecation warnings into test failures.
-    That makes it hard to deprecate whole modules, because they get
-    imported by default. So this is a special Deprecation warning that the
-    nose tester will let pass without making tests fail.
-
-    """
-    pass
-
-
-class VisibleDeprecationWarning(UserWarning):
-    """Visible deprecation warning.
-
-    By default, python will not show deprecation warnings, so this class
-    can be used when a very visible warning is helpful, for example because
-    the usage is most likely a user bug.
-
-    """
-    pass
-
-
-class _NoValue:
-    """Special keyword value.
-
-    This class may be used as the default value assigned to a
-    deprecated keyword in order to check if it has been given a user
-    defined value.
-    """
-    pass
-
-
-# oldnumeric and numarray were removed in 1.9. In case some packages import
-# but do not use them, we define them here for backward compatibility.
-oldnumeric = 'removed'
-numarray = 'removed'
-
+from ._globals import ModuleDeprecationWarning, VisibleDeprecationWarning
+from ._globals import _NoValue
 
 # We first need to detect if we're being called as part of the numpy setup
 # procedure itself in a reliable manner.
@@ -155,11 +119,8 @@ try:
 except NameError:
     __NUMPY_SETUP__ = False
 
-
 if __NUMPY_SETUP__:
-    import sys as _sys
-    _sys.stderr.write('Running from numpy source directory.\n')
-    del _sys
+    sys.stderr.write('Running from numpy source directory.\n')
 else:
     try:
         from numpy.__config__ import show as show_config
@@ -168,6 +129,7 @@ else:
         its source directory; please exit the numpy source tree, and relaunch
         your python interpreter from there."""
         raise ImportError(msg)
+
     from .version import git_revision as __git_revision__
     from .version import version as __version__
 
@@ -206,7 +168,7 @@ else:
     from .compat import long
 
     # Make these accessible from numpy name-space
-    #  but not imported in from numpy import *
+    # but not imported in from numpy import *
     if sys.version_info[0] >= 3:
         from builtins import bool, int, float, complex, object, str
         unicode = str
@@ -222,8 +184,13 @@ else:
     __all__.extend(lib.__all__)
     __all__.extend(['linalg', 'fft', 'random', 'ctypeslib', 'ma'])
 
+
     # Filter annoying Cython warnings that serve no good purpose.
-    import warnings
     warnings.filterwarnings("ignore", message="numpy.dtype size changed")
     warnings.filterwarnings("ignore", message="numpy.ufunc size changed")
     warnings.filterwarnings("ignore", message="numpy.ndarray size changed")
+
+    # oldnumeric and numarray were removed in 1.9. In case some packages import
+    # but do not use them, we define them here for backward compatibility.
+    oldnumeric = 'removed'
+    numarray = 'removed'
diff --git a/numpy/_globals.py b/numpy/_globals.py
new file mode 100644
index 0000000..64a84da
--- /dev/null
+++ b/numpy/_globals.py
@@ -0,0 +1,62 @@
+"""
+Module defining global singleton classes.
+
+This module raises a RuntimeError if an attempt to reload it is made. In that
+way the identities of the classes defined here are fixed and will remain so
+even if numpy itself is reloaded. In particular, a function like the following
+will still work correctly after numpy is reloaded::
+
+    def foo(arg=np._NoValue):
+        if arg is np._NoValue:
+            ...
+
+That was not the case when the singleton classes were defined in the numpy
+``__init__.py`` file. See gh-7844 for a discussion of the reload problem that
+motivated this module.
+
+"""
+from __future__ import division, absolute_import, print_function
+
+
+__ALL__ = [
+    'ModuleDeprecationWarning', 'VisibleDeprecationWarning', '_NoValue'
+    ]
+
+
+# Disallow reloading this module so as to preserve the identities of the
+# classes defined here.
+if '_is_loaded' in globals():
+    raise RuntimeError('Reloading numpy._globals is not allowed')
+_is_loaded = True
+
+
+class ModuleDeprecationWarning(DeprecationWarning):
+    """Module deprecation warning.
+
+    The nose tester turns ordinary Deprecation warnings into test failures.
+    That makes it hard to deprecate whole modules, because they get
+    imported by default. So this is a special Deprecation warning that the
+    nose tester will let pass without making tests fail.
+
+    """
+    pass
+
+
+class VisibleDeprecationWarning(UserWarning):
+    """Visible deprecation warning.
+
+    By default, python will not show deprecation warnings, so this class
+    can be used when a very visible warning is helpful, for example because
+    the usage is most likely a user bug.
+
+    """
+    pass
+
+
+class _NoValue:
+    """Special keyword value.
+
+    This class may be used as the default value assigned to a deprecated
+    keyword in order to check if it has been given a user defined value.
+    """
+    pass
diff --git a/numpy/_import_tools.py b/numpy/_import_tools.py
index 0d11d69..eda0284 100644
--- a/numpy/_import_tools.py
+++ b/numpy/_import_tools.py
@@ -52,7 +52,7 @@ class PackageLoader(object):
     def _init_info_modules(self, packages=None):
         """Initialize info_modules = {<package_name>: <package info.py module>}.
         """
-        import imp
+        from numpy.compat import npy_load_module
         info_files = []
         info_modules = self.info_modules
 
@@ -86,8 +86,7 @@ class PackageLoader(object):
                 filedescriptor = ('.py', 'U', 1)
 
             try:
-                info_module = imp.load_module(fullname+'.info',
-                                              open(info_file, filedescriptor[1]),
+                info_module = npy_load_module(fullname + '.info',
                                               info_file,
                                               filedescriptor)
             except Exception as msg:
diff --git a/numpy/compat/py3k.py b/numpy/compat/py3k.py
index d95a362..d46ac1f 100644
--- a/numpy/compat/py3k.py
+++ b/numpy/compat/py3k.py
@@ -7,7 +7,7 @@ from __future__ import division, absolute_import, print_function
 __all__ = ['bytes', 'asbytes', 'isfileobj', 'getexception', 'strchar',
            'unicode', 'asunicode', 'asbytes_nested', 'asunicode_nested',
            'asstr', 'open_latin1', 'long', 'basestring', 'sixu',
-           'integer_types']
+           'integer_types', 'npy_load_module']
 
 import sys
 
@@ -86,3 +86,61 @@ def asunicode_nested(x):
         return [asunicode_nested(y) for y in x]
     else:
         return asunicode(x)
+
+if sys.version_info[0] >= 3 and sys.version_info[1] >= 4:
+    def npy_load_module(name, fn, info=None):
+        """
+        Load a module.
+
+        .. versionadded:: 1.11.2
+
+        Parameters
+        ----------
+        name : str
+            Full module name.
+        fn : str
+            Path to module file.
+        info : tuple, optional
+            Only here for backward compatibility with Python 2.*.
+
+        Returns
+        -------
+        mod : module
+
+        """
+        import importlib
+        return importlib.machinery.SourceFileLoader(name, fn).load_module()
+else:
+    def npy_load_module(name, fn, info=None):
+        """
+        Load a module.
+
+        .. versionadded:: 1.11.2
+
+        Parameters
+        ----------
+        name : str
+            Full module name.
+        fn : str
+            Path to module file.
+        info : tuple, optional
+            Information as returned by `imp.find_module`
+            (suffix, mode, type).
+
+        Returns
+        -------
+        mod : module
+
+        """
+        import imp
+        import os
+        if info is None:
+            path = os.path.dirname(fn)
+            fo, fn, info = imp.find_module(name, [path])
+        else:
+            fo = open(fn, info[1])
+        try:
+            mod = imp.load_module(name, fo, fn, info)
+        finally:
+            fo.close()
+        return mod
diff --git a/numpy/core/code_generators/generate_umath.py b/numpy/core/code_generators/generate_umath.py
index b3d8f43..7a8d7ff 100644
--- a/numpy/core/code_generators/generate_umath.py
+++ b/numpy/core/code_generators/generate_umath.py
@@ -695,6 +695,7 @@ defdict = {
     Ufunc(1, 1, None,
           docstrings.get('numpy.core.umath.sqrt'),
           None,
+          TD('e', f='sqrt', astype={'e':'f'}),
           TD(inexactvec),
           TD(inexact, f='sqrt', astype={'e':'f'}),
           TD(P, f='sqrt'),
diff --git a/numpy/core/fromnumeric.py b/numpy/core/fromnumeric.py
index 4faeb55..bb89adb 100644
--- a/numpy/core/fromnumeric.py
+++ b/numpy/core/fromnumeric.py
@@ -17,7 +17,6 @@ from . import _methods
 
 _dt_ = nt.sctype2char
 
-
 # functions that are methods
 __all__ = [
     'alen', 'all', 'alltrue', 'amax', 'amin', 'any', 'argmax',
@@ -1380,6 +1379,7 @@ def trace(a, offset=0, axis1=0, axis2=1, dtype=None, out=None):
         return asanyarray(a).trace(offset, axis1, axis2, dtype, out)
 
 
+
 def ravel(a, order='C'):
     """Return a contiguous flattened array.
 
@@ -1740,7 +1740,7 @@ def clip(a, a_min, a_max, out=None):
     return clip(a_min, a_max, out)
 
 
-def sum(a, axis=None, dtype=None, out=None, keepdims=False):
+def sum(a, axis=None, dtype=None, out=None, keepdims=np._NoValue):
     """
     Sum of array elements over a given axis.
 
@@ -1770,9 +1770,15 @@ def sum(a, axis=None, dtype=None, out=None, keepdims=False):
         the same shape as the expected output, but the type of the output
         values will be cast if necessary.
     keepdims : bool, optional
-        If this is set to True, the axes which are reduced are left in the
-        result as dimensions with size one. With this option, the result
-        will broadcast correctly against the input array.
+        If this is set to True, the axes which are reduced are left
+        in the result as dimensions with size one. With this option,
+        the result will broadcast correctly against the original `arr`.
+
+        If the default value is passed, then `keepdims` will not be
+        passed through to the `sum` method of sub-classes of
+        `ndarray`, however any non-default value will be.  If the
+        sub-classes `sum` method does not implement `keepdims` any
+        exceptions will be raised.
 
     Returns
     -------
@@ -1821,6 +1827,9 @@ def sum(a, axis=None, dtype=None, out=None, keepdims=False):
     -128
 
     """
+    kwargs = {}
+    if keepdims is not np._NoValue:
+        kwargs['keepdims'] = keepdims
     if isinstance(a, _gentype):
         res = _sum_(a)
         if out is not None:
@@ -1832,15 +1841,14 @@ def sum(a, axis=None, dtype=None, out=None, keepdims=False):
             sum = a.sum
         except AttributeError:
             return _methods._sum(a, axis=axis, dtype=dtype,
-                                 out=out, keepdims=keepdims)
-        # NOTE: Dropping the keepdims parameters here...
-        return sum(axis=axis, dtype=dtype, out=out)
+                                out=out, **kwargs)
+        return sum(axis=axis, dtype=dtype, out=out, **kwargs)
     else:
         return _methods._sum(a, axis=axis, dtype=dtype,
-                             out=out, keepdims=keepdims)
+                            out=out, **kwargs)
 
 
-def product(a, axis=None, dtype=None, out=None, keepdims=False):
+def product(a, axis=None, dtype=None, out=None, keepdims=np._NoValue):
     """
     Return the product of array elements over a given axis.
 
@@ -1849,11 +1857,13 @@ def product(a, axis=None, dtype=None, out=None, keepdims=False):
     prod : equivalent function; see for details.
 
     """
-    return um.multiply.reduce(a, axis=axis, dtype=dtype,
-                              out=out, keepdims=keepdims)
+    kwargs = {}
+    if keepdims is not np._NoValue:
+        kwargs['keepdims'] = keepdims
+    return um.multiply.reduce(a, axis=axis, dtype=dtype, out=out, **kwargs)
 
 
-def sometrue(a, axis=None, out=None, keepdims=False):
+def sometrue(a, axis=None, out=None, keepdims=np._NoValue):
     """
     Check whether some values are true.
 
@@ -1865,14 +1875,13 @@ def sometrue(a, axis=None, out=None, keepdims=False):
 
     """
     arr = asanyarray(a)
-
-    try:
-        return arr.any(axis=axis, out=out, keepdims=keepdims)
-    except TypeError:
-        return arr.any(axis=axis, out=out)
+    kwargs = {}
+    if keepdims is not np._NoValue:
+        kwargs['keepdims'] = keepdims
+    return arr.any(axis=axis, out=out, **kwargs)
 
 
-def alltrue(a, axis=None, out=None, keepdims=False):
+def alltrue(a, axis=None, out=None, keepdims=np._NoValue):
     """
     Check if all elements of input array are true.
 
@@ -1882,14 +1891,13 @@ def alltrue(a, axis=None, out=None, keepdims=False):
 
     """
     arr = asanyarray(a)
+    kwargs = {}
+    if keepdims is not np._NoValue:
+        kwargs['keepdims'] = keepdims
+    return arr.all(axis=axis, out=out, **kwargs)
 
-    try:
-        return arr.all(axis=axis, out=out, keepdims=keepdims)
-    except TypeError:
-        return arr.all(axis=axis, out=out)
 
-
-def any(a, axis=None, out=None, keepdims=False):
+def any(a, axis=None, out=None, keepdims=np._NoValue):
     """
     Test whether any array element along a given axis evaluates to True.
 
@@ -1915,11 +1923,18 @@ def any(a, axis=None, out=None, keepdims=False):
         (e.g., if it is of type float, then it will remain so, returning
         1.0 for True and 0.0 for False, regardless of the type of `a`).
         See `doc.ufuncs` (Section "Output arguments") for details.
+
     keepdims : bool, optional
         If this is set to True, the axes which are reduced are left
         in the result as dimensions with size one. With this option,
         the result will broadcast correctly against the original `arr`.
 
+        If the default value is passed, then `keepdims` will not be
+        passed through to the `any` method of sub-classes of
+        `ndarray`, however any non-default value will be.  If the
+        sub-classes `sum` method does not implement `keepdims` any
+        exceptions will be raised.
+
     Returns
     -------
     any : bool or ndarray
@@ -1963,14 +1978,13 @@ def any(a, axis=None, out=None, keepdims=False):
 
     """
     arr = asanyarray(a)
-
-    try:
-        return arr.any(axis=axis, out=out, keepdims=keepdims)
-    except TypeError:
-        return arr.any(axis=axis, out=out)
+    kwargs = {}
+    if keepdims is not np._NoValue:
+        kwargs['keepdims'] = keepdims
+    return arr.any(axis=axis, out=out, **kwargs)
 
 
-def all(a, axis=None, out=None, keepdims=False):
+def all(a, axis=None, out=None, keepdims=np._NoValue):
     """
     Test whether all array elements along a given axis evaluate to True.
 
@@ -1994,11 +2008,18 @@ def all(a, axis=None, out=None, keepdims=False):
         type is preserved (e.g., if ``dtype(out)`` is float, the result
         will consist of 0.0's and 1.0's).  See `doc.ufuncs` (Section
         "Output arguments") for more details.
+
     keepdims : bool, optional
         If this is set to True, the axes which are reduced are left
         in the result as dimensions with size one. With this option,
         the result will broadcast correctly against the original `arr`.
 
+        If the default value is passed, then `keepdims` will not be
+        passed through to the `all` method of sub-classes of
+        `ndarray`, however any non-default value will be.  If the
+        sub-classes `sum` method does not implement `keepdims` any
+        exceptions will be raised.
+
     Returns
     -------
     all : ndarray, bool
@@ -2037,11 +2058,10 @@ def all(a, axis=None, out=None, keepdims=False):
 
     """
     arr = asanyarray(a)
-
-    try:
-        return arr.all(axis=axis, out=out, keepdims=keepdims)
-    except TypeError:
-        return arr.all(axis=axis, out=out)
+    kwargs = {}
+    if keepdims is not np._NoValue:
+        kwargs['keepdims'] = keepdims
+    return arr.all(axis=axis, out=out, **kwargs)
 
 
 def cumsum(a, axis=None, dtype=None, out=None):
@@ -2177,7 +2197,7 @@ def ptp(a, axis=None, out=None):
     return ptp(axis, out)
 
 
-def amax(a, axis=None, out=None, keepdims=False):
+def amax(a, axis=None, out=None, keepdims=np._NoValue):
     """
     Return the maximum of an array or maximum along an axis.
 
@@ -2197,11 +2217,18 @@ def amax(a, axis=None, out=None, keepdims=False):
         Alternative output array in which to place the result.  Must
         be of the same shape and buffer length as the expected output.
         See `doc.ufuncs` (Section "Output arguments") for more details.
+
     keepdims : bool, optional
         If this is set to True, the axes which are reduced are left
         in the result as dimensions with size one. With this option,
         the result will broadcast correctly against the original `arr`.
 
+        If the default value is passed, then `keepdims` will not be
+        passed through to the `amax` method of sub-classes of
+        `ndarray`, however any non-default value will be.  If the
+        sub-classes `sum` method does not implement `keepdims` any
+        exceptions will be raised.
+
     Returns
     -------
     amax : ndarray or scalar
@@ -2255,20 +2282,22 @@ def amax(a, axis=None, out=None, keepdims=False):
     4.0
 
     """
+    kwargs = {}
+    if keepdims is not np._NoValue:
+        kwargs['keepdims'] = keepdims
     if type(a) is not mu.ndarray:
         try:
             amax = a.max
         except AttributeError:
             return _methods._amax(a, axis=axis,
-                                  out=out, keepdims=keepdims)
-        # NOTE: Dropping the keepdims parameter
-        return amax(axis=axis, out=out)
+                                out=out, **kwargs)
+        return amax(axis=axis, out=out, **kwargs)
     else:
         return _methods._amax(a, axis=axis,
-                              out=out, keepdims=keepdims)
+                            out=out, **kwargs)
 
 
-def amin(a, axis=None, out=None, keepdims=False):
+def amin(a, axis=None, out=None, keepdims=np._NoValue):
     """
     Return the minimum of an array or minimum along an axis.
 
@@ -2288,11 +2317,18 @@ def amin(a, axis=None, out=None, keepdims=False):
         Alternative output array in which to place the result.  Must
         be of the same shape and buffer length as the expected output.
         See `doc.ufuncs` (Section "Output arguments") for more details.
+
     keepdims : bool, optional
         If this is set to True, the axes which are reduced are left
         in the result as dimensions with size one. With this option,
         the result will broadcast correctly against the original `arr`.
 
+        If the default value is passed, then `keepdims` will not be
+        passed through to the `amin` method of sub-classes of
+        `ndarray`, however any non-default value will be.  If the
+        sub-classes `sum` method does not implement `keepdims` any
+        exceptions will be raised.
+
     Returns
     -------
     amin : ndarray or scalar
@@ -2346,17 +2382,19 @@ def amin(a, axis=None, out=None, keepdims=False):
     0.0
 
     """
+    kwargs = {}
+    if keepdims is not np._NoValue:
+        kwargs['keepdims'] = keepdims
     if type(a) is not mu.ndarray:
         try:
             amin = a.min
         except AttributeError:
             return _methods._amin(a, axis=axis,
-                                  out=out, keepdims=keepdims)
-        # NOTE: Dropping the keepdims parameter
-        return amin(axis=axis, out=out)
+                                out=out, **kwargs)
+        return amin(axis=axis, out=out, **kwargs)
     else:
         return _methods._amin(a, axis=axis,
-                              out=out, keepdims=keepdims)
+                            out=out, **kwargs)
 
 
 def alen(a):
@@ -2392,7 +2430,7 @@ def alen(a):
         return len(array(a, ndmin=1))
 
 
-def prod(a, axis=None, dtype=None, out=None, keepdims=False):
+def prod(a, axis=None, dtype=None, out=None, keepdims=np._NoValue):
     """
     Return the product of array elements over a given axis.
 
@@ -2427,6 +2465,12 @@ def prod(a, axis=None, dtype=None, out=None, keepdims=False):
         result as dimensions with size one. With this option, the result
         will broadcast correctly against the input array.
 
+        If the default value is passed, then `keepdims` will not be
+        passed through to the `prod` method of sub-classes of
+        `ndarray`, however any non-default value will be.  If the
+        sub-classes `sum` method does not implement `keepdims` any
+        exceptions will be raised.
+
     Returns
     -------
     product_along_axis : ndarray, see `dtype` parameter above.
@@ -2484,16 +2528,19 @@ def prod(a, axis=None, dtype=None, out=None, keepdims=False):
     True
 
     """
+    kwargs = {}
+    if keepdims is not np._NoValue:
+        kwargs['keepdims'] = keepdims
     if type(a) is not mu.ndarray:
         try:
             prod = a.prod
         except AttributeError:
             return _methods._prod(a, axis=axis, dtype=dtype,
-                                  out=out, keepdims=keepdims)
-        return prod(axis=axis, dtype=dtype, out=out)
+                                out=out, **kwargs)
+        return prod(axis=axis, dtype=dtype, out=out, **kwargs)
     else:
         return _methods._prod(a, axis=axis, dtype=dtype,
-                              out=out, keepdims=keepdims)
+                            out=out, **kwargs)
 
 
 def cumprod(a, axis=None, dtype=None, out=None):
@@ -2793,7 +2840,7 @@ def round_(a, decimals=0, out=None):
     return round(decimals, out)
 
 
-def mean(a, axis=None, dtype=None, out=None, keepdims=False):
+def mean(a, axis=None, dtype=None, out=None, keepdims=np._NoValue):
     """
     Compute the arithmetic mean along the specified axis.
 
@@ -2823,11 +2870,18 @@ def mean(a, axis=None, dtype=None, out=None, keepdims=False):
         is ``None``; if provided, it must have the same shape as the
         expected output, but the type will be cast if necessary.
         See `doc.ufuncs` for details.
+
     keepdims : bool, optional
         If this is set to True, the axes which are reduced are left
         in the result as dimensions with size one. With this option,
         the result will broadcast correctly against the original `arr`.
 
+        If the default value is passed, then `keepdims` will not be
+        passed through to the `mean` method of sub-classes of
+        `ndarray`, however any non-default value will be.  If the
+        sub-classes `sum` method does not implement `keepdims` any
+        exceptions will be raised.
+
     Returns
     -------
     m : ndarray, see dtype parameter above
@@ -2874,18 +2928,21 @@ def mean(a, axis=None, dtype=None, out=None, keepdims=False):
     0.55000000074505806
 
     """
+    kwargs = {}
+    if keepdims is not np._NoValue:
+        kwargs['keepdims'] = keepdims
     if type(a) is not mu.ndarray:
         try:
             mean = a.mean
-            return mean(axis=axis, dtype=dtype, out=out)
+            return mean(axis=axis, dtype=dtype, out=out, **kwargs)
         except AttributeError:
             pass
 
     return _methods._mean(a, axis=axis, dtype=dtype,
-                          out=out, keepdims=keepdims)
+                            out=out, **kwargs)
 
 
-def std(a, axis=None, dtype=None, out=None, ddof=0, keepdims=False):
+def std(a, axis=None, dtype=None, out=None, ddof=0, keepdims=np._NoValue):
     """
     Compute the standard deviation along the specified axis.
 
@@ -2922,6 +2979,12 @@ def std(a, axis=None, dtype=None, out=None, ddof=0, keepdims=False):
         in the result as dimensions with size one. With this option,
         the result will broadcast correctly against the original `arr`.
 
+        If the default value is passed, then `keepdims` will not be
+        passed through to the `std` method of sub-classes of
+        `ndarray`, however any non-default value will be.  If the
+        sub-classes `sum` method does not implement `keepdims` any
+        exceptions will be raised.
+
     Returns
     -------
     standard_deviation : ndarray, see dtype parameter above.
@@ -2981,19 +3044,23 @@ def std(a, axis=None, dtype=None, out=None, ddof=0, keepdims=False):
     0.44999999925494177
 
     """
+    kwargs = {}
+    if keepdims is not np._NoValue:
+        kwargs['keepdims'] = keepdims
+
     if type(a) is not mu.ndarray:
         try:
             std = a.std
-            return std(axis=axis, dtype=dtype, out=out, ddof=ddof)
+            return std(axis=axis, dtype=dtype, out=out, ddof=ddof, **kwargs)
         except AttributeError:
             pass
 
     return _methods._std(a, axis=axis, dtype=dtype, out=out, ddof=ddof,
-                         keepdims=keepdims)
+                                **kwargs)
 
 
 def var(a, axis=None, dtype=None, out=None, ddof=0,
-        keepdims=False):
+                            keepdims=np._NoValue):
     """
     Compute the variance along the specified axis.
 
@@ -3031,6 +3098,12 @@ def var(a, axis=None, dtype=None, out=None, ddof=0,
         in the result as dimensions with size one. With this option,
         the result will broadcast correctly against the original `arr`.
 
+        If the default value is passed, then `keepdims` will not be
+        passed through to the `var` method of sub-classes of
+        `ndarray`, however any non-default value will be.  If the
+        sub-classes `sum` method does not implement `keepdims` any
+        exceptions will be raised.
+
     Returns
     -------
     variance : ndarray, see dtype parameter above
@@ -3089,12 +3162,16 @@ def var(a, axis=None, dtype=None, out=None, ddof=0,
     0.2025
 
     """
+    kwargs = {}
+    if keepdims is not np._NoValue:
+        kwargs['keepdims'] = keepdims
+
     if type(a) is not mu.ndarray:
         try:
             var = a.var
-            return var(axis=axis, dtype=dtype, out=out, ddof=ddof)
+            return var(axis=axis, dtype=dtype, out=out, ddof=ddof, **kwargs)
         except AttributeError:
             pass
 
     return _methods._var(a, axis=axis, dtype=dtype, out=out, ddof=ddof,
-                         keepdims=keepdims)
+                                **kwargs)
diff --git a/numpy/core/setup.py b/numpy/core/setup.py
index 3c3d160..ae7b4ba 100644
--- a/numpy/core/setup.py
+++ b/numpy/core/setup.py
@@ -1,6 +1,5 @@
 from __future__ import division, print_function
 
-import imp
 import os
 import sys
 import pickle
@@ -10,9 +9,10 @@ from os.path import join
 from numpy.distutils import log
 from distutils.dep_util import newer
 from distutils.sysconfig import get_config_var
-from numpy._build_utils.apple_accelerate import (uses_accelerate_framework,
-                                                 get_sgemv_fix)
-
+from numpy._build_utils.apple_accelerate import (
+    uses_accelerate_framework, get_sgemv_fix
+    )
+from numpy.compat import npy_load_module
 from setup_common import *
 
 # Set to True to enable relaxed strides checking. This (mostly) means
@@ -386,9 +386,8 @@ def configuration(parent_package='',top_path=None):
 
     generate_umath_py = join(codegen_dir, 'generate_umath.py')
     n = dot_join(config.name, 'generate_umath')
-    generate_umath = imp.load_module('_'.join(n.split('.')),
-                                     open(generate_umath_py, 'U'), generate_umath_py,
-                                     ('.py', 'U', 1))
+    generate_umath = npy_load_module('_'.join(n.split('.')),
+                                     generate_umath_py, ('.py', 'U', 1))
 
     header_dir = 'include/numpy'  # this is relative to config.path_in_package
 
diff --git a/numpy/core/src/multiarray/ctors.c b/numpy/core/src/multiarray/ctors.c
index 46753ac..fe121d6 100644
--- a/numpy/core/src/multiarray/ctors.c
+++ b/numpy/core/src/multiarray/ctors.c
@@ -900,9 +900,8 @@ PyArray_NewFromDescr_int(PyTypeObject *subtype, PyArray_Descr *descr, int nd,
                          int flags, PyObject *obj, int zeroed)
 {
     PyArrayObject_fields *fa;
-    int i;
-    size_t sd;
-    npy_intp size;
+    int i, is_empty;
+    npy_intp nbytes;
 
     if (descr->subarray) {
         PyObject *ret;
@@ -929,10 +928,9 @@ PyArray_NewFromDescr_int(PyTypeObject *subtype, PyArray_Descr *descr, int nd,
         return NULL;
     }
 
-    /* Check dimensions */
-    size = 1;
-    sd = (size_t) descr->elsize;
-    if (sd == 0) {
+    /* Check datatype element size */
+    nbytes = descr->elsize;
+    if (nbytes == 0) {
         if (!PyDataType_ISSTRING(descr)) {
             PyErr_SetString(PyExc_TypeError, "Empty data-type");
             Py_DECREF(descr);
@@ -943,13 +941,15 @@ PyArray_NewFromDescr_int(PyTypeObject *subtype, PyArray_Descr *descr, int nd,
             return NULL;
         }
         if (descr->type_num == NPY_STRING) {
-            sd = descr->elsize = 1;
+            nbytes = descr->elsize = 1;
         }
         else {
-            sd = descr->elsize = sizeof(npy_ucs4);
+            nbytes = descr->elsize = sizeof(npy_ucs4);
         }
     }
 
+    /* Check dimensions and multiply them to nbytes */
+    is_empty = 0;
     for (i = 0; i < nd; i++) {
         npy_intp dim = dims[i];
 
@@ -958,13 +958,13 @@ PyArray_NewFromDescr_int(PyTypeObject *subtype, PyArray_Descr *descr, int nd,
              * Compare to PyArray_OverflowMultiplyList that
              * returns 0 in this case.
              */
+            is_empty = 1;
             continue;
         }
 
         if (dim < 0) {
             PyErr_SetString(PyExc_ValueError,
-                            "negative dimensions "  \
-                            "are not allowed");
+                "negative dimensions are not allowed");
             Py_DECREF(descr);
             return NULL;
         }
@@ -974,9 +974,10 @@ PyArray_NewFromDescr_int(PyTypeObject *subtype, PyArray_Descr *descr, int nd,
          * multiplying the dimensions together to get the total size of the
          * array.
          */
-        if (npy_mul_with_overflow_intp(&size, size, dim)) {
+        if (npy_mul_with_overflow_intp(&nbytes, nbytes, dim)) {
             PyErr_SetString(PyExc_ValueError,
-                            "array is too big.");
+                "array is too big; `arr.size * arr.dtype.itemsize` "
+                "is larger than the maximum possible size.");
             Py_DECREF(descr);
             return NULL;
         }
@@ -1015,9 +1016,9 @@ PyArray_NewFromDescr_int(PyTypeObject *subtype, PyArray_Descr *descr, int nd,
         }
         fa->strides = fa->dimensions + nd;
         memcpy(fa->dimensions, dims, sizeof(npy_intp)*nd);
-        if (strides == NULL) { /* fill it in */
-            sd = _array_fill_strides(fa->strides, dims, nd, sd,
-                                     flags, &(fa->flags));
+        if (strides == NULL) {  /* fill it in */
+            _array_fill_strides(fa->strides, dims, nd, descr->elsize,
+                                flags, &(fa->flags));
         }
         else {
             /*
@@ -1025,7 +1026,6 @@ PyArray_NewFromDescr_int(PyTypeObject *subtype, PyArray_Descr *descr, int nd,
... 2786 lines suppressed ...

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-numpy.git



More information about the Python-modules-commits mailing list