diff options
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/__init__.py | 6 | ||||
-rw-r--r-- | numpy/lib/function_base.py | 14 | ||||
-rw-r--r-- | numpy/lib/tests/test_function_base.py | 9 | ||||
-rw-r--r-- | numpy/random/tests/test_random.py | 8 |
4 files changed, 30 insertions, 7 deletions
diff --git a/numpy/__init__.py b/numpy/__init__.py index 0b5357632..8a09d2fec 100644 --- a/numpy/__init__.py +++ b/numpy/__init__.py @@ -169,3 +169,9 @@ else: __all__.extend(_mat.__all__) __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") + diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index 247f16560..2b1d780d2 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -3591,19 +3591,21 @@ def insert(arr, obj, values, axis=None): slobj = [slice(None)]*ndim N = arr.shape[axis] newshape = list(arr.shape) - if isinstance(obj, (int, long, integer)): + if isinstance(obj, (int, long, integer)): if (obj < 0): obj += N if obj < 0 or obj > N: raise ValueError( "index (%d) out of range (0<=index<=%d) "\ "in dimension %d" % (obj, N, axis)) - - if isinstance(values, (int, long, integer)): - obj = [obj] + if isscalar(values): + obj = [obj] else: - obj = [obj] * len(values) - + values = asarray(values) + if ndim > values.ndim: + obj = [obj] + else: + obj = [obj] * len(values) elif isinstance(obj, slice): # turn it into a range object diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py index 7c1b01345..da3eb2b84 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -147,6 +147,15 @@ class TestInsert(TestCase): assert_equal(insert(a, [1, 1, 1], [1, 2, 3]), [1, 1, 2, 3, 2, 3]) assert_equal(insert(a, 1,[1,2,3]), [1, 1, 2, 3, 2, 3]) assert_equal(insert(a,[1,2,3],9),[1,9,2,9,3,9]) + b = np.array([0, 1], dtype=np.float64) + assert_equal(insert(b, 0, b[0]), [0., 0., 1.]) + def test_multidim(self): + a = [[1, 1, 1]] + r = [[2, 2, 2], + [1, 1, 1]] + assert_equal(insert(a, 0, [2, 2, 2], axis=0), r) + assert_equal(insert(a, 0, 2, axis=0), r) + assert_equal(insert(a, 2, 2, axis=1), [[1, 1, 2, 1]]) class TestAmax(TestCase): def test_basic(self): diff --git a/numpy/random/tests/test_random.py b/numpy/random/tests/test_random.py index 7d9163e61..ee40cce69 100644 --- a/numpy/random/tests/test_random.py +++ b/numpy/random/tests/test_random.py @@ -360,7 +360,13 @@ class TestRandomDist(TestCase): desired = np.array([[ 2.46852460439034849e+03, 1.41286880810518346e+03], [ 5.28287797029485181e+07, 6.57720981047328785e+07], [ 1.40840323350391515e+02, 1.98390255135251704e+05]]) - np.testing.assert_array_almost_equal(actual, desired, decimal=15) + # For some reason on 32-bit x86 Ubuntu 12.10 the [1, 0] entry in this + # matrix differs by 24 nulps. Discussion: + # http://mail.scipy.org/pipermail/numpy-discussion/2012-September/063801.html + # Consensus is that this is probably some gcc quirk that affects + # rounding but not in any important way, so we just use a looser + # tolerance on this test: + np.testing.assert_array_almost_equal_nulp(actual, desired, nulp=30) def test_poisson(self): np.random.seed(self.seed) |