[Numpy-discussion] Masked Array for NumPy 1.7

Nathaniel Smith njs at pobox.com
Sat May 19 12:01:45 EDT 2012


On Sat, May 19, 2012 at 4:21 PM, Mark Wiebe <mwwiebe at gmail.com> wrote:
> The motivation behind splitting the mask out into a separate ndmasked is
> primarily so that pre-existing code will not silently function on NA-masked
> arrays and produce incorrect results. This centres around using PyArray_DATA
> to get at the data after manually checking flags, instead of calling
> PyArray_FromAny. Maybe a reasonable solution is to tweak the behavior of
> PyArray_DATA? It could work as follows:
>
> - If an ndarray has no mask, PyArray_DATA returns the data pointer as it
> does currently.
> - If the ndarray has an NA-mask, PyArray_DATA sets an exception and returns
> NULL
> - Create a new accessor, PyArray_DATAPTR or PyArray_RAWDATA, which returns
> the array data under all circumstances.
>
> This way, code which currently uses the data pointer through PyArray_DATA
> will fail instead of silently working with the wrong interpretation of the
> data. What do people feel about this idea?

By "fail" you mean, specifically, segfault, right? PyArray_DATA
currently cannot fail or return NULL, so I doubt any existing code
checks for exceptions before dereferencing the pointer it returns.

- N



More information about the NumPy-Discussion mailing list