[Numpy-discussion] Bug in nanmin called with unsigned integers

Tony S Yu tsyu80 at gmail.com
Wed May 26 09:59:17 EDT 2010


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 at gmail.com> wrote:
> I got bit again by this bug with unsigned integers. (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).
> 
> 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.

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)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20100526/20b5c779/attachment.html>


More information about the NumPy-Discussion mailing list