diff options
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/core/src/multiarray/buffer.c | 4 | ||||
-rw-r--r-- | numpy/core/tests/test_maskna.py | 8 |
2 files changed, 12 insertions, 0 deletions
diff --git a/numpy/core/src/multiarray/buffer.c b/numpy/core/src/multiarray/buffer.c index 694207197..ac94d270e 100644 --- a/numpy/core/src/multiarray/buffer.c +++ b/numpy/core/src/multiarray/buffer.c @@ -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"); diff --git a/numpy/core/tests/test_maskna.py b/numpy/core/tests/test_maskna.py index 5aeb1d668..641f63ed9 100644 --- a/numpy/core/tests/test_maskna.py +++ b/numpy/core/tests/test_maskna.py @@ -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) |