[Numpy-discussion] MaskedArray __setitem__ for Record Values

Pierre GM pgmdevlist@gmail....
Fri Feb 15 11:59:38 CST 2008


On Friday 15 February 2008 10:51:04 Alexander Michael wrote:
> >>> d = numpy.empty((5,4), dtype=[('value', float),('source', int)])
> >>> a = ma.MaskedArray(d, mask=True, fill_value=(0.0,0))
> >>> a[0,0] = (10.0, 1)
>
> numpy\ma\core.py in __setitem__(self, indx, value)
>    1359             return
>    1360         #....
> -> 1361         dval = getdata(value).astype(self.dtype)
>    1362         valmask = getmask(value)
>    1363         if self._mask is nomask:
>
> TypeError: expected a readable buffer object

Good call.
The easiest is still to replace the line 1361 with:
dval = narray(value, copy=False, dtype=self.dtype)

The problem with the initial method was that the tuple got transformed into a 
(2,) array whose type could not be changed afterwards. With the new line, we 
directly transform value to a ndarray of the proper type.

Mmh. Where should I commit the fix ? Directly to the trunk ?


More information about the Numpy-discussion mailing list