Skip to content

Commit

Permalink
Merge pull request #3006 from seberg/fix-empty-item
Browse files Browse the repository at this point in the history
BUG: Fix regression of bad error/random behavior in item method
  • Loading branch information
charris committed Feb 20, 2013
2 parents b2ed8f7 + 04b89c6 commit 665a00a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions numpy/core/src/multiarray/methods.c
Expand Up @@ -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... :| */
Expand Down
5 changes: 5 additions & 0 deletions numpy/core/tests/test_regression.py
Expand Up @@ -1068,6 +1068,11 @@ def test_recarray_tolist(self, level=rlevel):
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']))
Expand Down

0 comments on commit 665a00a

Please sign in to comment.