diff options
Diffstat (limited to 'numpy')
| -rw-r--r-- | numpy/core/fromnumeric.py | 8 | ||||
| -rw-r--r-- | numpy/core/numeric.py | 6 | ||||
| -rw-r--r-- | numpy/core/src/multiarray/multiarraymodule.c | 3 | ||||
| -rw-r--r-- | numpy/core/tests/test_fromnumeric.py | 17 | ||||
| -rw-r--r-- | numpy/core/tests/test_multiarray.py | 2 | ||||
| -rw-r--r-- | numpy/core/tests/test_numeric.py | 14 | ||||
| -rw-r--r-- | numpy/lib/function_base.py | 6 | ||||
| -rw-r--r-- | numpy/lib/tests/test_function_base.py | 4 | ||||
| -rw-r--r-- | numpy/lib/tests/test_regression.py | 4 |
9 files changed, 54 insertions, 10 deletions
diff --git a/numpy/core/fromnumeric.py b/numpy/core/fromnumeric.py index 5d74bbda0..4faeb557a 100644 --- a/numpy/core/fromnumeric.py +++ b/numpy/core/fromnumeric.py @@ -445,7 +445,13 @@ def put(a, ind, v, mode='raise'): array([ 0, 1, 2, 3, -5]) """ - return a.put(ind, v, mode) + try: + put = a.put + except AttributeError: + raise TypeError("argument 1 must be numpy.ndarray, " + "not {name}".format(name=type(a).__name__)) + + return put(ind, v, mode) def swapaxes(a, axis1, axis2): diff --git a/numpy/core/numeric.py b/numpy/core/numeric.py index a18b38072..0b728f804 100644 --- a/numpy/core/numeric.py +++ b/numpy/core/numeric.py @@ -2467,7 +2467,11 @@ def isclose(a, b, rtol=1.e-5, atol=1.e-8, equal_nan=False): # Make NaN == NaN both_nan = isnan(x) & isnan(y) cond[both_nan] = both_nan[both_nan] - return cond + + if isscalar(a) and isscalar(b): + return bool(cond) + else: + return cond def array_equal(a1, a2): """ diff --git a/numpy/core/src/multiarray/multiarraymodule.c b/numpy/core/src/multiarray/multiarraymodule.c index 2c17ebe09..1df3d653d 100644 --- a/numpy/core/src/multiarray/multiarraymodule.c +++ b/numpy/core/src/multiarray/multiarraymodule.c @@ -827,6 +827,7 @@ PyArray_InnerProduct(PyObject *op1, PyObject *op2) typenum = PyArray_ObjectType(op2, typenum); typec = PyArray_DescrFromType(typenum); if (typec == NULL) { + PyErr_SetString(PyExc_TypeError, "Cannot find a common data type."); goto fail; } @@ -912,7 +913,7 @@ PyArray_MatrixProduct2(PyObject *op1, PyObject *op2, PyArrayObject* out) typenum = PyArray_ObjectType(op2, typenum); typec = PyArray_DescrFromType(typenum); if (typec == NULL) { - PyErr_SetString(PyExc_ValueError, "Cannot find a common data type."); + PyErr_SetString(PyExc_TypeError, "Cannot find a common data type."); return NULL; } diff --git a/numpy/core/tests/test_fromnumeric.py b/numpy/core/tests/test_fromnumeric.py new file mode 100644 index 000000000..0fba10b6e --- /dev/null +++ b/numpy/core/tests/test_fromnumeric.py @@ -0,0 +1,17 @@ +from __future__ import division, absolute_import, print_function + +from numpy import put +from numpy.testing import TestCase, assert_raises + + +class TestPut(TestCase): + + def test_bad_array(self): + # We want to raise a TypeError in the + # case that a non-ndarray object is passed + # in since `np.put` modifies in place and + # hence would do nothing to a non-ndarray + v = 5 + indx = [0, 2] + bad_array = [1, 2, 3] + assert_raises(TypeError, put, bad_array, indx, v) diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py index c9e610cbf..26617c1fc 100644 --- a/numpy/core/tests/test_multiarray.py +++ b/numpy/core/tests/test_multiarray.py @@ -2045,7 +2045,7 @@ class TestMethods(TestCase): c = 1. A = np.array((1,1), dtype='i,i') - assert_raises(ValueError, np.dot, c, A) + assert_raises(TypeError, np.dot, c, A) assert_raises(TypeError, np.dot, A, c) def test_diagonal(self): diff --git a/numpy/core/tests/test_numeric.py b/numpy/core/tests/test_numeric.py index a114d5a5a..17ea6212c 100644 --- a/numpy/core/tests/test_numeric.py +++ b/numpy/core/tests/test_numeric.py @@ -1589,7 +1589,11 @@ class TestIsclose(object): def tst_isclose_allclose(self, x, y): msg = "isclose.all() and allclose aren't same for %s and %s" - assert_array_equal(np.isclose(x, y).all(), np.allclose(x, y), msg % (x, y)) + msg2 = "isclose and allclose aren't same for %s and %s" + if np.isscalar(x) and np.isscalar(y): + assert_(np.isclose(x, y) == np.allclose(x, y), msg=msg % (x, y)) + else: + assert_array_equal(np.isclose(x, y).all(), np.allclose(x, y), msg % (x, y)) def test_ip_all_isclose(self): self.setup() @@ -1650,6 +1654,14 @@ class TestIsclose(object): assert_array_equal(x, np.array([np.inf, 1])) assert_array_equal(y, np.array([0, np.inf])) + def test_non_finite_scalar(self): + # GH7014, when two scalars are compared the output should also be a + # scalar + assert_(np.isclose(np.inf, -np.inf) is False) + assert_(np.isclose(0, np.inf) is False) + assert_(type(np.isclose(0, np.inf)) is bool) + + class TestStdVar(TestCase): def setUp(self): self.A = np.array([1, -1, 1, -1]) diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index 9bc128f92..844c069c0 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -1779,7 +1779,7 @@ def place(arr, mask, vals): Parameters ---------- - arr : array_like + arr : ndarray Array to put data into. mask : array_like Boolean mask array. Must have the same size as `a`. @@ -1801,6 +1801,10 @@ def place(arr, mask, vals): [44, 55, 44]]) """ + if not isinstance(arr, np.ndarray): + raise TypeError("argument 1 must be numpy.ndarray, " + "not {name}".format(name=type(arr).__name__)) + return _insert(arr, mask, vals) diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py index a5ac78e33..88a590517 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -674,6 +674,10 @@ class TestExtins(TestCase): assert_array_equal(b, [3, 2, 2, 3, 3]) def test_place(self): + # Make sure that non-np.ndarray objects + # raise an error instead of doing nothing + assert_raises(TypeError, place, [1, 2, 3], [True, False], [0, 1]) + a = np.array([1, 4, 3, 2, 5, 8, 7]) place(a, [0, 1, 0, 1, 0, 1, 0], [2, 4, 6]) assert_array_equal(a, [1, 2, 3, 4, 5, 6, 7]) diff --git a/numpy/lib/tests/test_regression.py b/numpy/lib/tests/test_regression.py index 00fa3f195..ee50dcfa4 100644 --- a/numpy/lib/tests/test_regression.py +++ b/numpy/lib/tests/test_regression.py @@ -85,10 +85,6 @@ class TestRegression(TestCase): assert_(x != y) assert_(x == x) - def test_mem_insert(self, level=rlevel): - # Ticket #572 - np.lib.place(1, 1, 1) - def test_polyfit_build(self): # Ticket #628 ref = [-1.06123820e-06, 5.70886914e-04, -1.13822012e-01, |
