[Numpy-svn] r6296 - trunk/numpy/ma

numpy-svn@scip... numpy-svn@scip...
Mon Jan 5 16:52:23 CST 2009


Author: pierregm
Date: 2009-01-05 16:52:21 -0600 (Mon, 05 Jan 2009)
New Revision: 6296

Modified:
   trunk/numpy/ma/core.py
Log:
*moved the printing templates out of MaskedArray.__repr__

Modified: trunk/numpy/ma/core.py
===================================================================
--- trunk/numpy/ma/core.py	2009-01-05 21:51:18 UTC (rev 6295)
+++ trunk/numpy/ma/core.py	2009-01-05 22:52:21 UTC (rev 6296)
@@ -1340,6 +1340,32 @@
             np.putmask(curdata, curmask, printopt)
     return
 
+_print_templates = dict(long = """\
+masked_%(name)s(data =
+ %(data)s,
+       %(nlen)s mask =
+ %(mask)s,
+ %(nlen)s fill_value = %(fill)s)
+""",
+                        short = """\
+masked_%(name)s(data = %(data)s,
+       %(nlen)s mask = %(mask)s,
+%(nlen)s  fill_value = %(fill)s)
+""",
+                        long_flx = """\
+masked_%(name)s(data =
+ %(data)s,
+       %(nlen)s mask =
+ %(mask)s,
+%(nlen)s  fill_value = %(fill)s,
+      %(nlen)s dtype = %(dtype)s)
+""",
+                        short_flx = """\
+masked_%(name)s(data = %(data)s,
+%(nlen)s        mask = %(mask)s,
+%(nlen)s  fill_value = %(fill)s,
+%(nlen)s       dtype = %(dtype)s)
+""")
 
 #####--------------------------------------------------------------------------
 #---- --- MaskedArray class ---
@@ -2245,43 +2271,18 @@
         """Literal string representation.
 
         """
-        with_mask = """\
-masked_%(name)s(data =
- %(data)s,
-      mask =
- %(mask)s,
-      fill_value=%(fill)s)
-"""
-        with_mask1 = """\
-masked_%(name)s(data = %(data)s,
-      mask = %(mask)s,
-      fill_value=%(fill)s)
-"""
-        with_mask_flx = """\
-masked_%(name)s(data =
- %(data)s,
-      mask =
- %(mask)s,
-      fill_value=%(fill)s,
-      dtype=%(dtype)s)
-"""
-        with_mask1_flx = """\
-masked_%(name)s(data = %(data)s,
-      mask = %(mask)s,
-      fill_value=%(fill)s
-      dtype=%(dtype)s)
-"""
         n = len(self.shape)
         name = repr(self._data).split('(')[0]
-        parameters =  dict(name=name, data=str(self), mask=str(self._mask),
+        parameters =  dict(name=name, nlen=" "*len(name),
+                           data=str(self), mask=str(self._mask),
                            fill=str(self.fill_value), dtype=str(self.dtype))
         if self.dtype.names:
             if n <= 1:
-                return with_mask1_flx % parameters
-            return  with_mask_flx % parameters
+                return _print_templates['short_flx'] % parameters
+            return  _print_templates['long_flx'] % parameters
         elif n <= 1:
-            return with_mask1 % parameters
-        return with_mask % parameters
+            return _print_templates['short'] % parameters
+        return _print_templates['long'] % parameters
     #............................................
     def __add__(self, other):
         "Add other to self, and return a new masked array."



More information about the Numpy-svn mailing list