Skip to content

Commit

Permalink
Merge pull request numpy#278 from mwiebe/NA_buffer_errorcheck
Browse files Browse the repository at this point in the history
BUG: maskna: PEP3118 code wasn't raising an error on NA-masked arrays
  • Loading branch information
mwiebe committed May 18, 2012
2 parents 5a86e25 + bfa66da commit 6594f47
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions numpy/core/src/multiarray/buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,10 @@ array_getbuffer(PyObject *obj, Py_buffer *view, int flags)
self = (PyArrayObject*)obj;

/* Check whether we can provide the wanted properties */
if (PyArray_HASMASKNA(obj)) {
PyErr_SetString(PyExc_TypeError, "NA-masked arrays are not supported by the Python buffer protocol");
goto fail;
}
if ((flags & PyBUF_C_CONTIGUOUS) == PyBUF_C_CONTIGUOUS &&
!PyArray_CHKFLAGS(self, NPY_ARRAY_C_CONTIGUOUS)) {
PyErr_SetString(PyExc_ValueError, "ndarray is not C-contiguous");
Expand Down
8 changes: 8 additions & 0 deletions numpy/core/tests/test_maskna.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ def test_array_maskna_construction():
assert_(a.flags.maskna)
assert_equal(np.isna(a), True)

@dec.skipif(sys.version_info < (2, 6))
def test_array_maskna_pep3188():
if sys.version_info[:2] == (2, 6):
from numpy.core.multiarray import memorysimpleview as memoryview

a = np.array([0, 1, np.NA], maskna=True)
# The buffer protocol doesn't support NA masks, should raise an error
assert_raises(TypeError, memoryview, a)

def test_array_maskna_asarray():
a = np.arange(6).reshape(2,3)
Expand Down

0 comments on commit 6594f47

Please sign in to comment.