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

Sandro Tosi morph at moszumanska.debian.org
Mon May 30 21:14:04 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 85990035f6289894f5812100e0aef3b91c354281
Author: Sandro Tosi <morph at debian.org>
Date:   Mon May 30 21:38:39 2016 +0100

    Import python-numpy_1.11.1~rc1.orig.tar.gz
---
 PKG-INFO                                   |  2 +-
 doc/release/1.11.1-notes.rst               | 28 ++++++++++++++++++
 doc/source/release.rst                     |  1 +
 numpy/core/src/multiarray/arraytypes.c.src |  7 +++++
 numpy/core/src/multiarray/item_selection.c | 13 +++++----
 numpy/core/src/multiarray/mapping.c        |  8 ++++--
 numpy/core/src/private/npy_config.h        |  4 +--
 numpy/core/tests/test_indexing.py          | 14 +++++++++
 numpy/core/tests/test_multiarray.py        |  9 ++++++
 numpy/distutils/fcompiler/intel.py         |  4 +--
 numpy/distutils/intelccompiler.py          |  4 +--
 numpy/distutils/npy_pkg_config.py          | 10 ++-----
 numpy/distutils/system_info.py             | 12 ++++++--
 numpy/distutils/tests/test_system_info.py  | 36 +++++++++++++++++++----
 numpy/lib/arraypad.py                      |  2 +-
 numpy/lib/function_base.py                 | 19 +++++++++---
 numpy/lib/tests/test_arraypad.py           | 13 +++++++++
 numpy/lib/tests/test_function_base.py      | 18 +++++++++++-
 numpy/linalg/linalg.py                     |  4 +--
 numpy/linalg/tests/test_regression.py      | 46 ++++++++++++++++++++++++++++++
 numpy/ma/core.py                           | 28 +++++++++++++-----
 numpy/ma/extras.py                         | 10 +++++--
 numpy/ma/tests/test_core.py                | 17 +++++++++++
 numpy/ma/tests/test_extras.py              | 13 +++++++++
 numpy/testing/utils.py                     |  8 ++++--
 numpy/version.py                           |  8 +++---
 setup.py                                   |  4 +--
 site.cfg.example                           |  1 +
 tools/swig/pyfragments.swg                 | 21 +++++++++-----
 29 files changed, 302 insertions(+), 62 deletions(-)

diff --git a/PKG-INFO b/PKG-INFO
index 34df102..0e97d49 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: numpy
-Version: 1.11.0
+Version: 1.11.1rc1
 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.1-notes.rst b/doc/release/1.11.1-notes.rst
new file mode 100644
index 0000000..072f01e
--- /dev/null
+++ b/doc/release/1.11.1-notes.rst
@@ -0,0 +1,28 @@
+NumPy 1.11.1 Release Notes
+**************************
+
+Numpy 1.11.1 supports Python 2.6 - 2.7 and 3.2 - 3.5. It fixes bugs and
+regressions found in Numpy 1.11.0 and includes several build related
+improvements. Wheels for Linux, Windows, and OSX can be found on pypi.
+
+Fixes Merged
+============
+
+- #7506 BUG: Make sure numpy imports on python 2.6 when nose is unavailable.
+- #7530 BUG: Floating exception with invalid axis in np.lexsort.
+- #7535 BUG: Extend glibc complex trig functions blacklist to glibc < 2.18.
+- #7551 BUG: Allow graceful recovery for no compiler.
+- #7558 BUG: Constant padding expected wrong type in constant_values.
+- #7578 BUG: Fix OverflowError in Python 3.x. in swig interface.
+- #7590 BLD: Fix configparser.InterpolationSyntaxError.
+- #7597 BUG: Make np.ma.take work on scalars.
+- #7608 BUG: linalg.norm(): Don't convert object arrays to float.
+- #7638 BLD: Correct C compiler customization in system_info.py.
+- #7654 BUG: ma.median of 1d array should return a scalar.
+- #7656 BLD: Remove hardcoded Intel compiler flag -xSSE4.2.
+- #7660 BUG: Temporary fix for str(mvoid) for object field types.
+- #7665 BUG: Fix incorrect printing of 1D masked arrays.
+- #7670 BUG: Correct initial index estimate in histogram.
+- #7671 BUG: Boolean assignment no GIL release when transfer needs API.
+- #7676 BUG: Fix handling of right edge of final histogram bin.
+- #7680 BUG: Fix np.clip bug NaN handling for Visual Studio 2015.
diff --git a/doc/source/release.rst b/doc/source/release.rst
index 6da6176..c6f9ab5 100644
--- a/doc/source/release.rst
+++ b/doc/source/release.rst
@@ -2,6 +2,7 @@
 Release Notes
 *************
 
+.. include:: ../release/1.11.1-notes.rst
 .. include:: ../release/1.11.0-notes.rst
 .. include:: ../release/1.10.4-notes.rst
 .. include:: ../release/1.10.3-notes.rst
diff --git a/numpy/core/src/multiarray/arraytypes.c.src b/numpy/core/src/multiarray/arraytypes.c.src
index b2ba831..59af754 100644
--- a/numpy/core/src/multiarray/arraytypes.c.src
+++ b/numpy/core/src/multiarray/arraytypes.c.src
@@ -3763,6 +3763,13 @@ static void
         }
     }
     else {
+        /*
+         * Visual Studio 2015 loop vectorizer handles NaN in an unexpected
+         * manner, see: https://github.com/numpy/numpy/issues/7601
+         */
+        #if (_MSC_VER == 1900)
+        #pragma loop( no_vector )
+        #endif
         for (i = 0; i < ni; i++) {
             if (@lt@(in[i], min_val)) {
                 out[i]   = min_val;
diff --git a/numpy/core/src/multiarray/item_selection.c b/numpy/core/src/multiarray/item_selection.c
index 64fa70b..a6ff5e7 100644
--- a/numpy/core/src/multiarray/item_selection.c
+++ b/numpy/core/src/multiarray/item_selection.c
@@ -1441,11 +1441,6 @@ PyArray_LexSort(PyObject *sort_keys, int axis)
             && PyDataType_FLAGCHK(PyArray_DESCR(mps[i]), NPY_NEEDS_PYAPI)) {
             object = 1;
         }
-        its[i] = (PyArrayIterObject *)PyArray_IterAllButAxis(
-                (PyObject *)mps[i], &axis);
-        if (its[i] == NULL) {
-            goto fail;
-        }
     }
 
     /* Now we can check the axis */
@@ -1472,6 +1467,14 @@ PyArray_LexSort(PyObject *sort_keys, int axis)
         goto fail;
     }
 
+    for (i = 0; i < n; i++) {
+        its[i] = (PyArrayIterObject *)PyArray_IterAllButAxis(
+                (PyObject *)mps[i], &axis);
+        if (its[i] == NULL) {
+            goto fail;
+        }
+    }
+
     /* Now do the sorting */
     ret = (PyArrayObject *)PyArray_New(&PyArray_Type, PyArray_NDIM(mps[0]),
                                        PyArray_DIMS(mps[0]), NPY_INTP,
diff --git a/numpy/core/src/multiarray/mapping.c b/numpy/core/src/multiarray/mapping.c
index 178740f..93f3fda 100644
--- a/numpy/core/src/multiarray/mapping.c
+++ b/numpy/core/src/multiarray/mapping.c
@@ -1258,7 +1258,9 @@ array_assign_boolean_subscript(PyArrayObject *self,
             return -1;
         }
 
-        NPY_BEGIN_THREADS_NDITER(iter);
+        if (!needs_api) {
+            NPY_BEGIN_THREADS_NDITER(iter);
+        }
 
         do {
             innersize = *NpyIter_GetInnerLoopSizePtr(iter);
@@ -1282,7 +1284,9 @@ array_assign_boolean_subscript(PyArrayObject *self,
             }
         } while (iternext(iter));
 
-        NPY_END_THREADS;
+        if (!needs_api) {
+            NPY_END_THREADS;
+        }
 
         NPY_AUXDATA_FREE(transferdata);
         NpyIter_Deallocate(iter);
diff --git a/numpy/core/src/private/npy_config.h b/numpy/core/src/private/npy_config.h
index 3d14706..5f8aa3b 100644
--- a/numpy/core/src/private/npy_config.h
+++ b/numpy/core/src/private/npy_config.h
@@ -75,7 +75,7 @@
 #include <features.h>
 
 #if defined(__GLIBC__)
-#if !__GLIBC_PREREQ(2, 16)
+#if !__GLIBC_PREREQ(2, 18)
 
 #undef HAVE_CASIN
 #undef HAVE_CASINF
@@ -96,7 +96,7 @@
 #undef HAVE_CACOSHF
 #undef HAVE_CACOSHL
 
-#endif /* __GLIBC_PREREQ(2, 16) */
+#endif /* __GLIBC_PREREQ(2, 18) */
 #endif /* defined(__GLIBC_PREREQ) */
 
 #endif /* defined(HAVE_FEATURES_H) */
diff --git a/numpy/core/tests/test_indexing.py b/numpy/core/tests/test_indexing.py
index 70029f8..a537a01 100644
--- a/numpy/core/tests/test_indexing.py
+++ b/numpy/core/tests/test_indexing.py
@@ -158,6 +158,20 @@ class TestIndexing(TestCase):
         assert_raises(ValueError, f, a, [1, 2, 3])
         assert_raises(ValueError, f, a[:1], [1, 2, 3])
 
+    def test_boolean_assignment_needs_api(self):
+        # See also gh-7666
+        # This caused a segfault on Python 2 due to the GIL not being
+        # held when the iterator does not need it, but the transfer function
+        # does
+        arr = np.zeros(1000)
+        indx = np.zeros(1000, dtype=bool)
+        indx[:100] = True
+        arr[indx] = np.ones(100, dtype=object)
+
+        expected = np.zeros(1000)
+        expected[:100] = 1
+        assert_array_equal(arr, expected)
+
     def test_boolean_indexing_twodim(self):
         # Indexing a 2-dimensional array with
         # 2-dimensional boolean array
diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py
index c73a0f3..51c6674 100644
--- a/numpy/core/tests/test_multiarray.py
+++ b/numpy/core/tests/test_multiarray.py
@@ -3396,6 +3396,12 @@ class TestClip(TestCase):
         x = val.clip(max=4)
         assert_(np.all(x <= 4))
 
+    def test_nan(self):
+        input_arr = np.array([-2., np.nan, 0.5, 3., 0.25, np.nan])
+        result = input_arr.clip(-1, 1)
+        expected = np.array([-1., np.nan, 0.5, 1., 0.25, np.nan])
+        assert_array_equal(result, expected)
+
 
 class TestCompress(TestCase):
     def test_axis(self):
@@ -3558,6 +3564,9 @@ class TestLexsort(TestCase):
             u, v = np.array(u, dtype='object'), np.array(v, dtype='object')
             assert_array_equal(idx, np.lexsort((u, v)))
 
+    def test_invalid_axis(self): # gh-7528
+        x = np.linspace(0., 1., 42*3).reshape(42, 3)
+        assert_raises(ValueError, np.lexsort, x, axis=2)
 
 class TestIO(object):
     """Test tofile, fromfile, tobytes, and fromstring"""
diff --git a/numpy/distutils/fcompiler/intel.py b/numpy/distutils/fcompiler/intel.py
index c4f15a0..f3e616e 100644
--- a/numpy/distutils/fcompiler/intel.py
+++ b/numpy/distutils/fcompiler/intel.py
@@ -123,7 +123,7 @@ class IntelEM64TFCompiler(IntelFCompiler):
         return ['-openmp -fp-model strict -O1']
 
     def get_flags_arch(self):
-        return ['-xSSE4.2']
+        return ['']
 
 # Is there no difference in the version string between the above compilers
 # and the Visual compilers?
@@ -205,7 +205,7 @@ class IntelEM64VisualFCompiler(IntelVisualFCompiler):
     version_match = simple_version_match(start='Intel\(R\).*?64,')
 
     def get_flags_arch(self):
-        return ['/QaxSSE4.2']
+        return ['']
 
 
 if __name__ == '__main__':
diff --git a/numpy/distutils/intelccompiler.py b/numpy/distutils/intelccompiler.py
index 20c6d2b..ee089db 100644
--- a/numpy/distutils/intelccompiler.py
+++ b/numpy/distutils/intelccompiler.py
@@ -54,7 +54,7 @@ class IntelEM64TCCompiler(UnixCCompiler):
     def __init__(self, verbose=0, dry_run=0, force=0):
         UnixCCompiler.__init__(self, verbose, dry_run, force)
         self.cc_exe = ('icc -m64 -fPIC -fp-model strict -O3 '
-                       '-fomit-frame-pointer -openmp -xSSE4.2')
+                       '-fomit-frame-pointer -openmp')
         compiler = self.cc_exe
         if platform.system() == 'Darwin':
             shared_flag = '-Wl,-undefined,dynamic_lookup'
@@ -88,7 +88,7 @@ if platform.system() == 'Windows':
             self.lib = self.find_exe('xilib')
             self.linker = self.find_exe('xilink')
             self.compile_options = ['/nologo', '/O3', '/MD', '/W3',
-                                    '/Qstd=c99', '/QaxSSE4.2']
+                                    '/Qstd=c99']
             self.compile_options_debug = ['/nologo', '/Od', '/MDd', '/W3',
                                           '/Qstd=c99', '/Z7', '/D_DEBUG']
 
diff --git a/numpy/distutils/npy_pkg_config.py b/numpy/distutils/npy_pkg_config.py
index fe64709..e7d6448 100644
--- a/numpy/distutils/npy_pkg_config.py
+++ b/numpy/distutils/npy_pkg_config.py
@@ -5,9 +5,9 @@ import re
 import os
 
 if sys.version_info[0] < 3:
-    from ConfigParser import SafeConfigParser, NoOptionError
+    from ConfigParser import RawConfigParser, NoOptionError
 else:
-    from configparser import ConfigParser, SafeConfigParser, NoOptionError
+    from configparser import RawConfigParser, NoOptionError
 
 __all__ = ['FormatError', 'PkgNotFound', 'LibraryInfo', 'VariableSet',
         'read_config', 'parse_flags']
@@ -259,11 +259,7 @@ def parse_config(filename, dirs=None):
     else:
         filenames = [filename]
 
-    if sys.version[:3] > '3.1':
-        # SafeConfigParser is deprecated in py-3.2 and renamed to ConfigParser
-        config = ConfigParser()
-    else:
-        config = SafeConfigParser()
+    config = RawConfigParser()
 
     n = config.read(filenames)
     if not len(n) >= 1:
diff --git a/numpy/distutils/system_info.py b/numpy/distutils/system_info.py
index a541bfa..459a2c4 100644
--- a/numpy/distutils/system_info.py
+++ b/numpy/distutils/system_info.py
@@ -128,9 +128,15 @@ import warnings
 from glob import glob
 from functools import reduce
 if sys.version_info[0] < 3:
-    from ConfigParser import NoOptionError, ConfigParser
+    from ConfigParser import NoOptionError
+    from ConfigParser import RawConfigParser as ConfigParser
 else:
-    from configparser import NoOptionError, ConfigParser
+    from configparser import NoOptionError
+    from configparser import RawConfigParser as ConfigParser
+# It seems that some people are importing ConfigParser from here so is
+# good to keep its class name. Use of RawConfigParser is needed in
+# order to be able to load path names with percent in them, like
+# `feature%2Fcool` which is common on git flow branch names.
 
 from distutils.errors import DistutilsError
 from distutils.dist import Distribution
@@ -1688,6 +1694,7 @@ class blas_info(system_info):
         # cblas or blas
         res = False
         c = distutils.ccompiler.new_compiler()
+        c.customize('')
         tmpdir = tempfile.mkdtemp()
         s = """#include <cblas.h>
         int main(int argc, const char *argv[])
@@ -1768,6 +1775,7 @@ class openblas_lapack_info(openblas_info):
     def check_embedded_lapack(self, info):
         res = False
         c = distutils.ccompiler.new_compiler()
+        c.customize('')
         tmpdir = tempfile.mkdtemp()
         s = """void zungqr();
         int main(int argc, const char *argv[])
diff --git a/numpy/distutils/tests/test_system_info.py b/numpy/distutils/tests/test_system_info.py
index 58ad05a..0f45cd7 100644
--- a/numpy/distutils/tests/test_system_info.py
+++ b/numpy/distutils/tests/test_system_info.py
@@ -3,6 +3,8 @@ from __future__ import division, print_function
 import os
 import shutil
 from tempfile import mkstemp, mkdtemp
+from subprocess import Popen, PIPE
+from distutils.errors import DistutilsError
 
 from numpy.distutils import ccompiler
 from numpy.testing import TestCase, run_module_suite, assert_, assert_equal
@@ -54,6 +56,27 @@ void bar(void) {
 }
 """
 
+def have_compiler():
+    """ Return True if there appears to be an executable compiler
+    """
+    compiler = ccompiler.new_compiler()
+    try:
+        cmd = compiler.compiler  # Unix compilers
+    except AttributeError:
+        try:
+            compiler.initialize()  # MSVC is different
+        except DistutilsError:
+            return False
+        cmd = [compiler.cc]
+    try:
+        Popen(cmd, stdout=PIPE, stderr=PIPE)
+    except OSError:
+        return False
+    return True
+
+
+HAVE_COMPILER = have_compiler()
+
 
 class test_system_info(system_info):
 
@@ -171,38 +194,39 @@ class TestSystemInfoReading(TestCase):
         extra = tsi.calc_extra_info()
         assert_equal(extra['extra_link_args'], ['-Wl,-rpath=' + self._lib2])
 
+    @skipif(not HAVE_COMPILER)
     def test_compile1(self):
         # Compile source and link the first source
         c = ccompiler.new_compiler()
+        previousDir = os.getcwd()
         try:
             # Change directory to not screw up directories
-            previousDir = os.getcwd()
             os.chdir(self._dir1)
             c.compile([os.path.basename(self._src1)], output_dir=self._dir1)
             # Ensure that the object exists
             assert_(os.path.isfile(self._src1.replace('.c', '.o')) or
                     os.path.isfile(self._src1.replace('.c', '.obj')))
+        finally:
             os.chdir(previousDir)
-        except OSError:
-            pass
 
+    @skipif(not HAVE_COMPILER)
     @skipif('msvc' in repr(ccompiler.new_compiler()))
     def test_compile2(self):
         # Compile source and link the second source
         tsi = self.c_temp2
         c = ccompiler.new_compiler()
         extra_link_args = tsi.calc_extra_info()['extra_link_args']
+        previousDir = os.getcwd()
         try:
             # Change directory to not screw up directories
-            previousDir = os.getcwd()
             os.chdir(self._dir2)
             c.compile([os.path.basename(self._src2)], output_dir=self._dir2,
                       extra_postargs=extra_link_args)
             # Ensure that the object exists
             assert_(os.path.isfile(self._src2.replace('.c', '.o')))
+        finally:
             os.chdir(previousDir)
-        except OSError:
-            pass
+
 
 if __name__ == '__main__':
     run_module_suite()
diff --git a/numpy/lib/arraypad.py b/numpy/lib/arraypad.py
index c30ef6b..3cfb105 100644
--- a/numpy/lib/arraypad.py
+++ b/numpy/lib/arraypad.py
@@ -1052,7 +1052,7 @@ def _normalize_shape(ndarray, shape, cast_to_int=True):
             arr = arr.repeat(2, axis=1)
         elif arr.shape[0] == ndims:
             # Input correctly formatted, pass it on as `arr`
-            arr = shape
+            pass
         else:
             fmt = "Unable to create correctly shaped tuple from %s"
             raise ValueError(fmt % (shape,))
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py
index 44e0d5c..85efaa9 100644
--- a/numpy/lib/function_base.py
+++ b/numpy/lib/function_base.py
@@ -565,6 +565,9 @@ def histogram(a, bins=10, range=None, normed=False, weights=None,
         # Pre-compute histogram scaling factor
         norm = bins / (mx - mn)
 
+        # Compute the bin edges for potential correction.
+        bin_edges = linspace(mn, mx, bins + 1, endpoint=True)
+
         # We iterate over blocks here for two reasons: the first is that for
         # large arrays, it is actually faster (for example for a 10^8 array it
         # is 2x as fast) and it results in a memory footprint 3x lower in the
@@ -583,8 +586,8 @@ def histogram(a, bins=10, range=None, normed=False, weights=None,
                 tmp_a = tmp_a[keep]
                 if tmp_w is not None:
                     tmp_w = tmp_w[keep]
-            tmp_a = tmp_a.astype(float)
-            tmp_a -= mn
+            tmp_a_data = tmp_a.astype(float)
+            tmp_a = tmp_a_data - mn
             tmp_a *= norm
 
             # Compute the bin indices, and for values that lie exactly on mx we
@@ -592,6 +595,14 @@ def histogram(a, bins=10, range=None, normed=False, weights=None,
             indices = tmp_a.astype(np.intp)
             indices[indices == bins] -= 1
 
+            # The index computation is not guaranteed to give exactly
+            # consistent results within ~1 ULP of the bin edges.
+            decrement = tmp_a_data < bin_edges[indices]
+            indices[decrement] -= 1
+            # The last bin includes the right edge. The other bins do not.
+            increment = (tmp_a_data >= bin_edges[indices + 1]) & (indices != bins - 1)
+            indices[increment] += 1
+
             # We now compute the histogram using bincount
             if ntype.kind == 'c':
                 n.real += np.bincount(indices, weights=tmp_w.real, minlength=bins)
@@ -599,8 +610,8 @@ def histogram(a, bins=10, range=None, normed=False, weights=None,
             else:
                 n += np.bincount(indices, weights=tmp_w, minlength=bins).astype(ntype)
 
-        # We now compute the bin edges since these are returned
-        bins = linspace(mn, mx, bins + 1, endpoint=True)
+        # Rename the bin edges for return.
+        bins = bin_edges
     else:
         bins = asarray(bins)
         if (np.diff(bins) < 0).any():
diff --git a/numpy/lib/tests/test_arraypad.py b/numpy/lib/tests/test_arraypad.py
index f19a0b1..9ad0590 100644
--- a/numpy/lib/tests/test_arraypad.py
+++ b/numpy/lib/tests/test_arraypad.py
@@ -477,6 +477,19 @@ class TestConstant(TestCase):
             )
         assert_allclose(test, expected)
 
+    def test_check_constant_pad_2d(self):
+        arr = np.arange(4).reshape(2, 2)
+        test = np.lib.pad(arr, ((1, 2), (1, 3)), mode='constant',
+                          constant_values=((1, 2), (3, 4)))
+        expected = np.array(
+            [[3, 1, 1, 4, 4, 4],
+             [3, 0, 1, 4, 4, 4],
+             [3, 2, 3, 4, 4, 4],
+             [3, 2, 2, 4, 4, 4],
+             [3, 2, 2, 4, 4, 4]]
+        )
+        assert_allclose(test, expected)
+
 
 class TestLinearRamp(TestCase):
     def test_check_simple(self):
diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py
index ea10cbc..5c57246 100644
--- a/numpy/lib/tests/test_function_base.py
+++ b/numpy/lib/tests/test_function_base.py
@@ -1276,7 +1276,23 @@ class TestHistogram(TestCase):
         histogram(vals, range=[0.25,0.75])
         assert_raises(ValueError, histogram, vals, range=[np.nan,0.75])
         assert_raises(ValueError, histogram, vals, range=[0.25,np.inf])
-        
+
+    def test_bin_edge_cases(self):
+        # Ensure that floating-point computations correctly place edge cases.
+        arr = np.array([337, 404, 739, 806, 1007, 1811, 2012])
+        hist, edges = np.histogram(arr, bins=8296, range=(2, 2280))
+        mask = hist > 0
+        left_edges = edges[:-1][mask]
+        right_edges = edges[1:][mask]
+        for x, left, right in zip(arr, left_edges, right_edges):
+            assert_(x >= left)
+            assert_(x < right)
+
+    def test_last_bin_inclusive_range(self):
+        arr = np.array([0.,  0.,  0.,  1.,  2.,  3.,  3.,  4.,  5.])
+        hist, edges = np.histogram(arr, bins=30, range=(-0.5, 5))
+        self.assertEqual(hist[-1], 1)
+
 
 class TestHistogramOptimBinNums(TestCase):
     """
diff --git a/numpy/linalg/linalg.py b/numpy/linalg/linalg.py
index 9d486d2..f4acd0e 100644
--- a/numpy/linalg/linalg.py
+++ b/numpy/linalg/linalg.py
@@ -23,7 +23,7 @@ from numpy.core import (
     csingle, cdouble, inexact, complexfloating, newaxis, ravel, all, Inf, dot,
     add, multiply, sqrt, maximum, fastCopyAndTranspose, sum, isfinite, size,
     finfo, errstate, geterrobj, longdouble, rollaxis, amin, amax, product, abs,
-    broadcast, atleast_2d, intp, asanyarray, isscalar
+    broadcast, atleast_2d, intp, asanyarray, isscalar, object_
     )
 from numpy.lib import triu, asfarray
 from numpy.linalg import lapack_lite, _umath_linalg
@@ -2112,7 +2112,7 @@ def norm(x, ord=None, axis=None, keepdims=False):
     """
     x = asarray(x)
 
-    if not issubclass(x.dtype.type, inexact):
+    if not issubclass(x.dtype.type, (inexact, object_)):
         x = x.astype(float)
 
     # Immediately handle some default, simple, fast, and common cases.
diff --git a/numpy/linalg/tests/test_regression.py b/numpy/linalg/tests/test_regression.py
index 54a67bc..6991628 100644
--- a/numpy/linalg/tests/test_regression.py
+++ b/numpy/linalg/tests/test_regression.py
@@ -90,6 +90,52 @@ class TestRegression(TestCase):
                 assert_equal(np.linalg.matrix_rank(a), 1)
                 assert_array_less(1, np.linalg.norm(a, ord=2))
 
+    def test_norm_object_array(self):
+        # gh-7575
+        testvector = np.array([np.array([0, 1]), 0, 0], dtype=object)
+
+        norm = linalg.norm(testvector)
+        assert_array_equal(norm, [0, 1])
+        self.assertEqual(norm.dtype, np.dtype('float64'))
+
+        norm = linalg.norm(testvector, ord=1)
+        assert_array_equal(norm, [0, 1])
+        self.assertNotEqual(norm.dtype, np.dtype('float64'))
+
+        norm = linalg.norm(testvector, ord=2)
+        assert_array_equal(norm, [0, 1])
+        self.assertEqual(norm.dtype, np.dtype('float64'))
+
+        self.assertRaises(ValueError, linalg.norm, testvector, ord='fro')
+        self.assertRaises(ValueError, linalg.norm, testvector, ord='nuc')
+        self.assertRaises(ValueError, linalg.norm, testvector, ord=np.inf)
+        self.assertRaises(ValueError, linalg.norm, testvector, ord=-np.inf)
+        self.assertRaises((AttributeError, DeprecationWarning),
+                          linalg.norm, testvector, ord=0)
+        self.assertRaises(ValueError, linalg.norm, testvector, ord=-1)
+        self.assertRaises(ValueError, linalg.norm, testvector, ord=-2)
+
+        testmatrix = np.array([[np.array([0, 1]), 0, 0],
+                               [0,                0, 0]], dtype=object)
+
+        norm = linalg.norm(testmatrix)
+        assert_array_equal(norm, [0, 1])
+        self.assertEqual(norm.dtype, np.dtype('float64'))
+
+        norm = linalg.norm(testmatrix, ord='fro')
+        assert_array_equal(norm, [0, 1])
+        self.assertEqual(norm.dtype, np.dtype('float64'))
+
+        self.assertRaises(TypeError, linalg.norm, testmatrix, ord='nuc')
+        self.assertRaises(ValueError, linalg.norm, testmatrix, ord=np.inf)
+        self.assertRaises(ValueError, linalg.norm, testmatrix, ord=-np.inf)
+        self.assertRaises(ValueError, linalg.norm, testmatrix, ord=0)
+        self.assertRaises(ValueError, linalg.norm, testmatrix, ord=1)
+        self.assertRaises(ValueError, linalg.norm, testmatrix, ord=-1)
+        self.assertRaises(TypeError, linalg.norm, testmatrix, ord=2)
+        self.assertRaises(TypeError, linalg.norm, testmatrix, ord=-2)
+        self.assertRaises(ValueError, linalg.norm, testmatrix, ord=3)
+
 
 if __name__ == '__main__':
     run_module_suite()
diff --git a/numpy/ma/core.py b/numpy/ma/core.py
index 5740771..e4f1a95 100644
--- a/numpy/ma/core.py
+++ b/numpy/ma/core.py
@@ -2698,8 +2698,11 @@ class MaskedArray(ndarray):
     _defaultmask = nomask
     _defaulthardmask = False
     _baseclass = ndarray
-    # Maximum number of elements per axis used when printing an array.
+
+    # Maximum number of elements per axis used when printing an array. The
+    # 1d case is handled separately because we need more values in this case.
     _print_width = 100
+    _print_width_1d = 1500
 
     def __new__(cls, data=None, mask=nomask, dtype=None, copy=False,
                 subok=True, ndmin=0, fill_value=None, keep_mask=True,
@@ -3776,9 +3779,11 @@ class MaskedArray(ndarray):
                     mask = m
                     # For big arrays, to avoid a costly conversion to the
                     # object dtype, extract the corners before the conversion.
+                    print_width = (self._print_width if self.ndim > 1
+                                   else self._print_width_1d)
                     for axis in range(self.ndim):
-                        if data.shape[axis] > self._print_width:
-                            ind = self._print_width // 2
+                        if data.shape[axis] > print_width:
+                            ind = print_width // 2
                             arr = np.split(data, (ind, -ind), axis=axis)
                             data = np.concatenate((arr[0], arr[2]), axis=axis)
                             arr = np.split(mask, (ind, -ind), axis=axis)
@@ -5628,9 +5633,10 @@ class MaskedArray(ndarray):
         maskindices = getattr(indices, '_mask', nomask)
         if maskindices is not nomask:
             indices = indices.filled(0)
-        # Get the data
+        # Get the data, promoting scalars to 0d arrays with [...] so that
+        # .view works correctly
         if out is None:
-            out = _data.take(indices, axis=axis, mode=mode).view(cls)
+            out = _data.take(indices, axis=axis, mode=mode)[...].view(cls)
         else:
             np.take(_data, indices, axis=axis, mode=mode, out=out)
         # Get the mask
@@ -5641,7 +5647,8 @@ class MaskedArray(ndarray):
                 outmask = _mask.take(indices, axis=axis, mode=mode)
                 outmask |= maskindices
             out.__setmask__(outmask)
-        return out
+        # demote 0d arrays back to scalars, for consistency with ndarray.take
+        return out[()]
 
     # Array methods
     copy = _arraymethod('copy')
@@ -5952,7 +5959,14 @@ class mvoid(MaskedArray):
             return self._data.__str__()
         printopt = masked_print_option
         rdtype = _recursive_make_descr(self._data.dtype, "O")
-        res = np.array([self._data]).astype(rdtype)
+
+        # temporary hack to fix gh-7493. A more permanent fix
+        # is proposed in gh-6053, after which the next two
+        # lines should be changed to
+        # res = np.array([self._data], dtype=rdtype)
+        res = np.empty(1, rdtype)
+        res[:1] = self._data
+
         _recursive_printoption(res, self._mask, printopt)
         return str(res[0])
 
diff --git a/numpy/ma/extras.py b/numpy/ma/extras.py
index 6e09165..dead02e 100644
--- a/numpy/ma/extras.py
+++ b/numpy/ma/extras.py
@@ -27,7 +27,7 @@ import warnings
 
 from . import core as ma
 from .core import (
-    MaskedArray, MAError, add, array, asarray, concatenate, filled,
+    MaskedArray, MAError, add, array, asarray, concatenate, filled, count,
     getmask, getmaskarray, make_mask_descr, masked, masked_array, mask_or,
     nomask, ones, sort, zeros, getdata, get_masked_subclass, dot,
     mask_rowcols
@@ -680,6 +680,10 @@ def median(a, axis=None, out=None, overwrite_input=False):
     elif axis < 0:
         axis += a.ndim
 
+    if asorted.ndim == 1:
+        idx, odd = divmod(count(asorted), 2)
+        return asorted[idx - (not odd) : idx + 1].mean()
+
     counts = asorted.shape[axis] - (asorted.mask).sum(axis=axis)
     h = counts // 2
     # create indexing mesh grid for all but reduced axis
@@ -688,10 +692,10 @@ def median(a, axis=None, out=None, overwrite_input=False):
     ind = np.meshgrid(*axes_grid, sparse=True, indexing='ij')
     # insert indices of low and high median
     ind.insert(axis, h - 1)
-    low = asorted[ind]
+    low = asorted[tuple(ind)]
     low._sharedmask = False
     ind[axis] = h
-    high = asorted[ind]
+    high = asorted[tuple(ind)]
     # duplicate high if odd number of elements so mean does nothing
     odd = counts % 2 == 1
     if asorted.ndim == 1:
diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py
index b163d3b..7f9b36d 100644
--- a/numpy/ma/tests/test_core.py
+++ b/numpy/ma/tests/test_core.py
@@ -451,6 +451,15 @@ class TestMaskedArray(TestCase):
                               '             mask = [False  True False],\n'
                               '       fill_value = 999999)\n')
 
+        a = np.ma.arange(2000)
+        a[1:50] = np.ma.masked
+        assert_equal(
+            repr(a),
+            'masked_array(data = [0 -- -- ..., 1997 1998 1999],\n'
+            '             mask = [False  True  True ..., False False False],\n'
+            '       fill_value = 999999)\n'
+        )
+
     def test_pickling(self):
         # Tests pickling
         a = arange(10)
@@ -757,6 +766,10 @@ class TestMaskedArray(TestCase):
         finally:
             masked_print_option.set_display(ini_display)
 
+        # also check if there are object datatypes (see gh-7493)
+        mx = array([(1,), (2,)], dtype=[('a', 'O')])
+        assert_equal(str(mx[0]), "(1,)")
+
     def test_mvoid_multidim_print(self):
 
         # regression test for gh-6019
@@ -2955,6 +2968,10 @@ class TestMaskedArrayMethods(TestCase):
         assert_equal(x.take([[0, 1], [0, 1]]),
                      masked_array([[10, 20], [10, 20]], [[0, 1], [0, 1]]))
 
+        # assert_equal crashes when passed np.ma.mask
+        self.assertTrue(x[1] is np.ma.masked)
+        self.assertTrue(x.take(1) is np.ma.masked)
+
         x = array([[10, 20, 30], [40, 50, 60]], mask=[[0, 0, 1], [1, 0, 0, ]])
         assert_equal(x.take([0, 2], axis=1),
                      array([[10, 30], [40, 60]], mask=[[0, 1], [1, 0]]))
diff --git a/numpy/ma/tests/test_extras.py b/numpy/ma/tests/test_extras.py
index 6138d05..e916dcf 100644
--- a/numpy/ma/tests/test_extras.py
+++ b/numpy/ma/tests/test_extras.py
@@ -662,6 +662,19 @@ class TestMedian(TestCase):
         assert_equal(np.ma.median(np.arange(9)), 4.)
         assert_equal(np.ma.median(range(9)), 4)
 
+    def test_masked_1d(self):
+        "test the examples given in the docstring of ma.median"
+        x = array(np.arange(8), mask=[0]*4 + [1]*4)
+        assert_equal(np.ma.median(x), 1.5)
+        assert_equal(np.ma.median(x).shape, (), "shape mismatch")
+        x = array(np.arange(10).reshape(2, 5), mask=[0]*6 + [1]*4)
+        assert_equal(np.ma.median(x), 2.5)
+        assert_equal(np.ma.median(x).shape, (), "shape mismatch")
+
+    def test_1d_shape_consistency(self):
+        assert_equal(np.ma.median(array([1,2,3],mask=[0,0,0])).shape,
+                     np.ma.median(array([1,2,3],mask=[0,1,0])).shape )
+
     def test_2d(self):
         # Tests median w/ 2D
         (n, p) = (101, 30)
diff --git a/numpy/testing/utils.py b/numpy/testing/utils.py
index f258878..09b58be 100644
--- a/numpy/testing/utils.py
+++ b/numpy/testing/utils.py
@@ -47,8 +47,12 @@ try:
     from unittest.case import SkipTest
 except ImportError:
     # on py2.6 unittest.case is not available. Ask nose for a replacement.
-    SkipTest = import_nose().SkipTest
-
+    try:
+        import nose
+        SkipTest = nose.SkipTest
+    except (ImportError, AttributeError):
+        # if nose is not available, testing won't work anyway
+        pass
 
 verbose = 0
 
diff --git a/numpy/version.py b/numpy/version.py
index a9ab6fb..b7f3bb2 100644
--- a/numpy/version.py
+++ b/numpy/version.py
@@ -2,10 +2,10 @@
 # THIS FILE IS GENERATED FROM NUMPY SETUP.PY
 #
 # To compare versions robustly, use `numpy.lib.NumpyVersion`
-short_version = '1.11.0'
-version = '1.11.0'
-full_version = '1.11.0'
-git_revision = '4092a9e160cc247a4a45724579a0c829733688ca'
+short_version = '1.11.1rc1'
+version = '1.11.1rc1'
+full_version = '1.11.1rc1'
+git_revision = 'abcb51151634c09b0db4eb462939f910555b7971'
 release = True
 
 if not release:
diff --git a/setup.py b/setup.py
index cc8f3c1..ae40778 100755
--- a/setup.py
+++ b/setup.py
@@ -58,9 +58,9 @@ Operating System :: MacOS
 
 MAJOR               = 1
 MINOR               = 11
-MICRO               = 0
+MICRO               = 1
 ISRELEASED          = True
-VERSION             = '%d.%d.%d' % (MAJOR, MINOR, MICRO)
+VERSION             = '%d.%d.%drc1' % (MAJOR, MINOR, MICRO)
 
 
 # Return the git revision as a string
diff --git a/site.cfg.example b/site.cfg.example
index 64eedb7..7f80c65 100644
--- a/site.cfg.example
+++ b/site.cfg.example
@@ -8,6 +8,7 @@
 # will also be checked for the file ~/.numpy-site.cfg .
 
 # The format of the file is that of the standard library's ConfigParser module.
+# No interpolation is allowed, RawConfigParser class being used to load it.
 #
 #   http://docs.python.org/3/library/configparser.html
 #
diff --git a/tools/swig/pyfragments.swg b/tools/swig/pyfragments.swg
index b5decf1..901e6ed 100644
--- a/tools/swig/pyfragments.swg
+++ b/tools/swig/pyfragments.swg
@@ -75,15 +75,22 @@
   SWIG_AsVal_dec(unsigned long)(PyObject *obj, unsigned long *val)
   {
     PyArray_Descr * ulongDescr = PyArray_DescrNewFromType(NPY_ULONG);
-    if (PyInt_Check(obj)) {
+    %#if PY_VERSION_HEX < 0x03000000
+    if (PyInt_Check(obj)) 
+    {
       long v = PyInt_AsLong(obj);
-      if (v >= 0) {
-	if (val) *val = v;
-	return SWIG_OK;
-      } else {
-	return SWIG_OverflowError;
+      if (v >= 0) 
+      {
+        if (val) *val = v;
+	    return SWIG_OK;
+      } 
+      else 
+      {
+	    return SWIG_OverflowError;
       }
-    } else if (PyLong_Check(obj)) {
+    } else 
+    %#endif
+    if (PyLong_Check(obj)) {
       unsigned long v = PyLong_AsUnsignedLong(obj);
       if (!PyErr_Occurred()) {
 	if (val) *val = v;

-- 
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