8000 BUG: Fix regression of bad error/random behavior in item method · numpy/numpy@b84555a · GitHub
[go: up one dir, main page]

Skip to content

Commit b84555a

Browse files
committed
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.
1 parent 695fe20 commit b84555a

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

numpy/core/src/multiarray/methods.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,7 @@ array_toscalar(PyArrayObject *self, PyObject *args)
633633
else {
634634
PyErr_SetString(PyExc_ValueError,
635635
"can only convert an array of size 1 to a Python scalar");
636+
return NULL;
636637
}
637638
}
638639
/* Special case of C-order flat indexing... :| */

numpy/core/tests/test_regression.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,11 @@ def test_recarray_tolist(self, level=rlevel):
10321032
assert_( a[0].tolist() == b[0])
10331033
assert_( a[1].tolist() == b[1])
10341034

1035+
def test_nonscalar_item_method(self):
1036+
# Make sure that .item() fails graciously when it should
1037+
a = np.arange(5)
1038+
assert_raises(ValueError, a.item)
1039+
10351040
def test_char_array_creation(self, level=rlevel):
10361041
a = np.array('123', dtype='c')
10371042
b = np.array(asbytes_nested(['1','2','3']))

0 commit comments

Comments
 (0)
0