[Scipy-svn] r3463 - in trunk/scipy/sandbox/maskedarray: . tests

scipy-svn@scip... scipy-svn@scip...
Thu Oct 25 14:04:04 CDT 2007


Author: pierregm
Date: 2007-10-25 14:03:56 -0500 (Thu, 25 Oct 2007)
New Revision: 3463

Modified:
   trunk/scipy/sandbox/maskedarray/core.py
   trunk/scipy/sandbox/maskedarray/tests/test_core.py
   trunk/scipy/sandbox/maskedarray/tests/test_extras.py
Log:
core: fixed imag and real

Modified: trunk/scipy/sandbox/maskedarray/core.py
===================================================================
--- trunk/scipy/sandbox/maskedarray/core.py	2007-10-25 17:09:53 UTC (rev 3462)
+++ trunk/scipy/sandbox/maskedarray/core.py	2007-10-25 19:03:56 UTC (rev 3463)
@@ -1528,6 +1528,20 @@
             raise MAError, 'Cannot convert masked element to a Python int.'
         return int(self.item())
     #............................................
+    def get_imag(self):
+        result = self._data.imag.view(type(self))
+        result.__setmask__(self._mask)
+        return result
+    imag = property(fget=get_imag,doc="Imaginary part")
+    
+    def get_real(self):
+        result = self._data.real.view(type(self))
+        result.__setmask__(self._mask)
+        return result
+    real = property(fget=get_real,doc="Real part")
+    
+        
+    #............................................
     def count(self, axis=None):
         """Counts the non-masked elements of the array along the given axis.
 
@@ -2955,4 +2969,11 @@
         assert_equal(mxbig.all(1), [False, False, True])
         assert_equal(mxbig.any(0),[False, False, True])
         assert_equal(mxbig.any(1), [True, True, True])
+        
+    if 1:
+        xx = array([1+10j,20+2j], mask=[1,0])
+        assert_equal(xx.imag,[10,2])
+        assert_equal(xx.imag.filled(), [1e+20,2])
+        assert_equal(xx.real,[1,20])
+        assert_equal(xx.real.filled(), [1e+20,20])
     
\ No newline at end of file

Modified: trunk/scipy/sandbox/maskedarray/tests/test_core.py
===================================================================
--- trunk/scipy/sandbox/maskedarray/tests/test_core.py	2007-10-25 17:09:53 UTC (rev 3462)
+++ trunk/scipy/sandbox/maskedarray/tests/test_core.py	2007-10-25 19:03:56 UTC (rev 3463)
@@ -783,6 +783,15 @@
         data_fixed = fix_invalid(data)
         assert_equal(data_fixed._data, [data.fill_value, 0., 1.])
         assert_equal(data_fixed._mask, [1., 0., 1.])    
+    #
+    def check_imag_real(self):
+        xx = array([1+10j,20+2j], mask=[1,0])
+        assert_equal(xx.imag,[10,2])
+        assert_equal(xx.imag.filled(), [1e+20,2])
+        assert_equal(xx.imag.dtype, xx._data.imag.dtype)
+        assert_equal(xx.real,[1,20])
+        assert_equal(xx.real.filled(), [1e+20,20])
+        assert_equal(xx.real.dtype, xx._data.real.dtype)
         
 #...............................................................................
         

Modified: trunk/scipy/sandbox/maskedarray/tests/test_extras.py
===================================================================
--- trunk/scipy/sandbox/maskedarray/tests/test_extras.py	2007-10-25 17:09:53 UTC (rev 3462)
+++ trunk/scipy/sandbox/maskedarray/tests/test_extras.py	2007-10-25 19:03:56 UTC (rev 3463)
@@ -330,4 +330,4 @@
 if __name__ == "__main__":
     NumpyTest().run()
 
-    
+    
\ No newline at end of file



More information about the Scipy-svn mailing list