diff options
author | Sebastian Berg <sebastian@sipsolutions.net> | 2013-02-20 15:04:33 +0100 |
---|---|---|
committer | Sebastian Berg <sebastian@sipsolutions.net> | 2013-02-20 15:11:21 +0100 |
commit | 04b89c63e531ee29b8a0cdb3f2c5ce410f6169b2 (patch) | |
tree | f25480688b0132babcf1a3b605da01a9eb0d9fc0 /numpy/core | |
parent | 4bf5a3feb00fe1d63e7d8fcf852cbf34e22fd60b (diff) | |
download | numpy-04b89c63e531ee29b8a0cdb3f2c5ce410f6169b2.tar.gz |
BUG: Fix regression of bad error/random behavior in item method
Appearently .item() for arrays with size != 1 correctly returned an error
in 1.6., but failed to raise the error (due to missing return) in 1.7.
Diffstat (limited to 'numpy/core')
-rw-r--r-- | numpy/core/src/multiarray/methods.c | 1 | ||||
-rw-r--r-- | numpy/core/tests/test_regression.py | 5 |
2 files changed, 6 insertions, 0 deletions
diff --git a/numpy/core/src/multiarray/methods.c b/numpy/core/src/multiarray/methods.c index 7f0e3861b..902384b0d 100644 --- a/numpy/core/src/multiarray/methods.c +++ b/numpy/core/src/multiarray/methods.c @@ -633,6 +633,7 @@ array_toscalar(PyArrayObject *self, PyObject *args) else { PyErr_SetString(PyExc_ValueError, "can only convert an array of size 1 to a Python scalar"); + return NULL; } } /* Special case of C-order flat indexing... :| */ diff --git a/numpy/core/tests/test_regression.py b/numpy/core/tests/test_regression.py index 1cf2e6e85..9a193b3c1 100644 --- a/numpy/core/tests/test_regression.py +++ b/numpy/core/tests/test_regression.py @@ -1068,6 +1068,11 @@ class TestRegression(TestCase): assert_( a[0].tolist() == b[0]) assert_( a[1].tolist() == b[1]) + def test_nonscalar_item_method(self): + # Make sure that .item() fails graciously when it should + a = np.arange(5) + assert_raises(ValueError, a.item) + def test_char_array_creation(self, level=rlevel): a = np.array('123', dtype='c') b = np.array(asbytes_nested(['1','2','3'])) |