diff options
author | Mark Wiebe <mwwiebe@gmail.com> | 2012-05-10 16:22:27 -0500 |
---|---|---|
committer | Mark Wiebe <mwwiebe@gmail.com> | 2012-05-10 16:22:27 -0500 |
commit | bfa66da9bddf4bd50a0c098d8d2dc79b17e8b4a2 (patch) | |
tree | 25a1ed015c2e21d67e274976e81d5662734007be /numpy | |
parent | bfaaefe52fd5ad3cb5d0a1c75061d9866716babe (diff) | |
download | numpy-bfa66da9bddf4bd50a0c098d8d2dc79b17e8b4a2.tar.gz |
BUG: maskna: PEP3118 code wasn't raising an error on NA-masked arrays
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) |