Permalink
Browse files

Merge pull request #278 from mwiebe/NA_buffer_errorcheck

BUG: maskna: PEP3118 code wasn't raising an error on NA-masked arrays
  • Loading branch information...
2 parents 5a86e25 + bfa66da commit 6594f47b0119950fbf5f247601a26e8bb9516d92 @mwiebe mwiebe committed May 18, 2012
Showing with 12 additions and 0 deletions.
  1. +4 −0 numpy/core/src/multiarray/buffer.c
  2. +8 −0 numpy/core/tests/test_maskna.py
@@ -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");
@@ -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)

0 comments on commit 6594f47

Please sign in to comment.