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

Skip to content

Commit 04b89c6

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 4bf5a3f commit 04b89c6

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
@@ -1068,6 +1068,11 @@ def test_recarray_tolist(self, level=rlevel):
10681068
assert_( a[0].tolist() == b[0])
10691069
assert_( a[1].tolist() == b[1])
10701070

1071+
def test_nonscalar_item_method(self):
1072+
# Make sure that .item() fails graciously when it should
1073+
a = np.arange(5)
1074+
assert_raises(ValueError, a.item)
1075+
10711076
def test_char_array_creation(self, level=rlevel):
10721077
a = np.array('123', dtype='c')
10731078
b = np.array(asbytes_nested(['1','2','3']))

0 commit comments

Comments
 (0)
0