On Wed, May 26, 2010 at 7:59 AM, Tony S Yu <tsyu80@gmail.com> wrote:
On May 25, 2010, at 10:57 PM, Charles R Harris wrote:
On Tue, May 25, 2010 at 8:21 PM, Tony S Yu <tsyu80@gmail.com> wrote:
I got bit again by this bug with unsigned integers<http://projects.scipy.org/numpy/ticket/1300>. (My original changes got overwritten when I updated from svn and, unfortunately, merged conflicts without actually looking over the changes.)
In any case, I thought it'd be a good time to bump the issue (with patch<http://projects.scipy.org/numpy/ticket/1300#comment:2> ).
Cheers, -Tony
PS: Just for context, this issue comes up when displaying images with Chaco (which converts images to unsigned integer arrays and calls nanmin).
Fixed in r8445. Please add some tests.
I'm not totally sure what's appropriate to test, so I just added a simple test to the comments for the ticket<http://projects.scipy.org/numpy/ticket/1300#comment:4> .
On a side note, I noticed that all the nan-ops degenerate to their non-nan-ops counterparts (i.e. nanmin --> min) when called with integer dtypes. Below is a diff where that's made a little more obvious by returning early for integer dtypes.
Cheers, -Tony
Index: numpy/lib/function_base.py =================================================================== --- numpy/lib/function_base.py (revision 8445) +++ numpy/lib/function_base.py (working copy) @@ -1295,15 +1295,15 @@
""" y = array(a, subok=True) - mask = isnan(a)
# We only need to take care of NaN's in floating point arrays - if not np.issubdtype(y.dtype, np.integer): - # y[mask] = fill - # We can't use fancy indexing here as it'll mess w/ MaskedArrays - # Instead, let's fill the array directly... - np.putmask(y, mask, fill) - + if np.issubdtype(y.dtype, np.integer): + return op(y, axis=axis) + mask = isnan(a) + # y[mask] = fill + # We can't use fancy indexing here as it'll mess w/ MaskedArrays + # Instead, let's fill the array directly... + np.putmask(y, mask, fill) res = op(y, axis=axis) mask_all_along_axis = mask.all(axis=axis)
Applied. Thanks.