[Numpy-discussion] Masked Arrays in NumPy 1.x

Frédéric Bastien nouiz at nouiz.org
Tue Apr 24 11:03:26 EDT 2012


Hi,

I finished reading the doc I listed in the other thread. As the NA
stuff will be marked as Experimental in numpy 1.7, why not define a
new macro like NPY_NA_VERSION that will give the version of the NA
C-api? That way, people will be able to detect if there is change in
the c-api of NA when they write it. So this will allow to break this
interface more easily. We would just need to make a big warning to do
this check it.

The current NPY_VERSION and NPY_FEATURE_VERSION macro don't allow
removing feature. Probably a function like PyArray_GetNACVersion would
be useful too.[1]

Continuing on my previous post, old code need to be changed to don't
accept NA inputs.  With the current trunk, this can be done like this:

PyObject* an_input = ....;

if (!PyArray_Check(an_input) {
    PyErr_SetString(PyExc_ValueError, "expected an ndarray");
    %(fail)s
}

if (NPY_FEATURE_VERSION >= 0x00000008){
   if(PyArray_HasNASupport((PyArrayObject*) an_input )){
          PyErr_SetString(PyExc_ValueError, "masked array are not
supported by this function");
          %(fail)s
   }
}

In the 1.6.1 release, NPY_FEATURE_VERSION had value 0x00000007. This
value wasn't changed in the trunk. I suppose it will be raised to
0x00000008 for numpy 1.7.

Can we suppose that old code check input with PyArray_Check()? I think
so, but it would be really helpful if  people that are here for longer
them me can confirm/deny this?

Frédéric

[1] http://docs.scipy.org/doc/numpy/reference/c-api.array.html#checking-the-api-version



More information about the NumPy-Discussion mailing list