summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark <mwwiebe@gmail.com>2012-05-18 13:56:31 -0700
committerMark <mwwiebe@gmail.com>2012-05-18 13:56:31 -0700
commit6594f47b0119950fbf5f247601a26e8bb9516d92 (patch)
treefe31339abba316344a2d84723dba88502607f590
parent5a86e25b5680595b066615ac97ae97bec63a56fc (diff)
parentbfa66da9bddf4bd50a0c098d8d2dc79b17e8b4a2 (diff)
downloadnumpy-6594f47b0119950fbf5f247601a26e8bb9516d92.tar.gz
Merge pull request #278 from mwiebe/NA_buffer_errorcheck
BUG: maskna: PEP3118 code wasn't raising an error on NA-masked arrays
-rw-r--r--numpy/core/src/multiarray/buffer.c4
-rw-r--r--numpy/core/tests/test_maskna.py8
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)