Revision: 5791
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5791&view=rev
Author:   astraw
Date:     2008-07-18 23:15:37 +0000 (Fri, 18 Jul 2008)

Log Message:
-----------
Check for nan and inf in axes.delete_masked_points().

Modified Paths:
--------------
    trunk/matplotlib/CHANGELOG
    trunk/matplotlib/lib/matplotlib/axes.py

Added Paths:
-----------
    trunk/matplotlib/unit/axes_unit.py

Modified: trunk/matplotlib/CHANGELOG
===================================================================
--- trunk/matplotlib/CHANGELOG  2008-07-18 20:43:58 UTC (rev 5790)
+++ trunk/matplotlib/CHANGELOG  2008-07-18 23:15:37 UTC (rev 5791)
@@ -1,3 +1,6 @@
+2008-07-18 Check for nan and inf in axes.delete_masked_points().
+          This should help hexbin and scatter deal with nans. - ADS
+
 2008-07-17 Added ability to manually select contour label locations.
           Also added a waitforbuttonpress function. - DMK
 

Modified: trunk/matplotlib/lib/matplotlib/axes.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/axes.py     2008-07-18 20:43:58 UTC (rev 
5790)
+++ trunk/matplotlib/lib/matplotlib/axes.py     2008-07-18 23:15:37 UTC (rev 
5791)
@@ -1,5 +1,5 @@
 from __future__ import division, generators
-import math, sys, warnings, datetime, new
+import math, sys, warnings, datetime, new, types
 
 import numpy as np
 from numpy import ma
@@ -36,6 +36,8 @@
     Find all masked points in a set of arguments, and return
     the arguments with only the unmasked points remaining.
 
+    This will also delete any points that are not finite (nan or inf).
+
     The overall mask is calculated from any masks that are present.
     If a mask is found, any argument that does not have the same
     dimensions is left unchanged; therefore the argument list may
@@ -49,9 +51,11 @@
     useful.
     """
     masks = [ma.getmaskarray(x) for x in args if hasattr(x, 'mask')]
+    isfinite = [np.isfinite(x) for x in args]
+    masks.extend( [~x for x in isfinite if not 
isinstance(x,types.NotImplementedType)] )
     if len(masks) == 0:
         return args
-    mask = reduce(ma.mask_or, masks)
+    mask = reduce(np.logical_or, masks)
     margs = []
     for x in args:
         if (not is_string_like(x)

Added: trunk/matplotlib/unit/axes_unit.py
===================================================================
--- trunk/matplotlib/unit/axes_unit.py                          (rev 0)
+++ trunk/matplotlib/unit/axes_unit.py  2008-07-18 23:15:37 UTC (rev 5791)
@@ -0,0 +1,62 @@
+import unittest
+import numpy as np
+import matplotlib.axes as axes
+
+class TestAxes(unittest.TestCase):
+    def test_delete_masked_points_arrays(self):
+        input = (   [1,2,3,np.nan,5],
+                    np.array((1,2,3,4,5)),
+                    )
+        expected = [np.array((1,2,3,5))]*2
+        actual = axes.delete_masked_points(*input)
+        assert np.allclose(actual, expected)
+
+        input = (   np.ma.array( [1,2,3,4,5], 
mask=[False,False,False,True,False] ),
+                    np.array((1,2,3,4,5)),
+                    )
+        expected = [np.array((1,2,3,5))]*2
+        actual = axes.delete_masked_points(*input)
+        assert np.allclose(actual, expected)
+
+        input = (   [1,2,3,np.nan,5],
+                    np.ma.array( [1,2,3,4,5], 
mask=[False,False,False,True,False] ),
+                    np.array((1,2,3,4,5)),
+                    )
+        expected = [np.array((1,2,3,5))]*3
+        actual = axes.delete_masked_points(*input)
+        assert np.allclose(actual, expected)
+
+        input = ()
+        expected = ()
+        actual = axes.delete_masked_points(*input)
+        assert np.allclose(actual, expected)
+
+
+        input = (   [1,2,3,np.nan,5],
+                    )
+        expected = [np.array((1,2,3,5))]*1
+        actual = axes.delete_masked_points(*input)
+        assert np.allclose(actual, expected)
+
+        input = (   np.array((1,2,3,4,5)),
+                    )
+        expected = [np.array((1,2,3,4,5))]*1
+        actual = axes.delete_masked_points(*input)
+        assert np.allclose(actual, expected)
+
+    def test_delete_masked_points_strings(self):
+        input = (   'hello',
+                    )
+        expected = ('hello',)
+        actual = axes.delete_masked_points(*input)
+        assert actual == expected
+
+        input = (   u'hello',
+                    )
+        expected = (u'hello',)
+        actual = axes.delete_masked_points(*input)
+        assert actual == expected
+
+
+if __name__=='__main__':
+    unittest.main()


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to