Skip to content

Commit

Permalink
PyArray_FromBuffer: Allow creating arrays from empty buffers or empty…
Browse files Browse the repository at this point in the history
… slices.
  • Loading branch information
Hrvoje Niksic authored and charris committed Oct 1, 2011
1 parent 10ed90c commit dadf7ed
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 3 additions & 3 deletions numpy/core/src/multiarray/ctors.c
Expand Up @@ -3610,10 +3610,10 @@ PyArray_FromBuffer(PyObject *buf, PyArray_Descr *type,
}
}

if ((offset < 0) || (offset >= ts)) {
if ((offset < 0) || (offset > ts)) {
PyErr_Format(PyExc_ValueError,
"offset must be non-negative and smaller than buffer "\
"lenth (%" INTP_FMT ")", (npy_intp)ts);
"offset must be non-negative and no greater than buffer "\
"length (%" INTP_FMT ")", (npy_intp)ts);
Py_DECREF(buf);
Py_DECREF(type);
return NULL;
Expand Down
3 changes: 3 additions & 0 deletions numpy/core/tests/test_multiarray.py
Expand Up @@ -1350,6 +1350,9 @@ def test_ip_basic(self):
buf = x.tostring()
yield self.tst_basic,buf,x.flat,{'dtype':dt}

def test_empty(self):
yield self.tst_basic, '', np.array([]), {}


class TestResize(TestCase):
def test_basic(self):
Expand Down

0 comments on commit dadf7ed

Please sign in to comment.