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

numpy-svn@scip... numpy-svn@scip...
Tue Aug 26 17:19:46 CDT 2008


Author: pierregm
Date: 2008-08-26 17:19:44 -0500 (Tue, 26 Aug 2008)
New Revision: 5707

Modified:
   trunk/numpy/ma/core.py
   trunk/numpy/ma/extras.py
Log:
Updated doc + -OO compatibility

Modified: trunk/numpy/ma/core.py
===================================================================
--- trunk/numpy/ma/core.py	2008-08-26 19:32:02 UTC (rev 5706)
+++ trunk/numpy/ma/core.py	2008-08-26 22:19:44 UTC (rev 5707)
@@ -81,8 +81,17 @@
 
 
 
-def doc_note(note):
-    return "\nNotes\n-----\n%s" % note
+def doc_note(initialdoc, note):
+    if initialdoc is None:
+        return
+    newdoc = """
+    %s
+    
+    Notes
+    -----
+    %s
+    """
+    return newdoc % (initialdoc, note)
 
 #####--------------------------------------------------------------------------
 #---- --- Exceptions ---
@@ -781,7 +790,7 @@
         return m.dtype.type is MaskType
     except AttributeError:
         return False
-#
+
 def make_mask(m, copy=False, shrink=True, flag=None):
     """Return m as a mask, creating a copy if necessary or requested.
 
@@ -865,14 +874,16 @@
         return m1
     return make_mask(umath.logical_or(m1, m2), copy=copy, shrink=shrink)
 
+
 #####--------------------------------------------------------------------------
 #--- --- Masking functions ---
 #####--------------------------------------------------------------------------
+
 def masked_where(condition, a, copy=True):
-    """Return a as an array masked where condition is true.
+    """
+    Return ``a`` as an array masked where ``condition`` is True.
+    Masked values of ``a`` or ``condition`` are kept.
 
-    Masked values of a or condition are kept.
-
     Parameters
     ----------
     condition : array_like
@@ -880,7 +891,7 @@
     a : array_like
         Array to mask.
     copy : bool
-        Whether to return a copy of a (True) or modify a in place.
+        Whether to return a copy of ``a`` (True) or modify ``a`` in place (False).
 
     """
     cond = make_mask(condition)
@@ -920,8 +931,9 @@
     return masked_where(not_equal(x, value), x, copy=copy)
 
 def masked_equal(x, value, copy=True):
-    """Shortcut to masked_where, with condition = (x == value).  For
-    floating point, consider `masked_values(x, value)` instead.
+    """
+    Shortcut to masked_where, with condition = (x == value).  For
+    floating point, consider ``masked_values(x, value)`` instead.
 
     """
     # An alternative implementation relies on filling first: probably not needed.
@@ -932,7 +944,8 @@
     return masked_where(equal(x, value), x, copy=copy)
 
 def masked_inside(x, v1, v2, copy=True):
-    """Shortcut to masked_where, where condition is True for x inside
+    """
+    Shortcut to masked_where, where ``condition`` is True for x inside
     the interval [v1,v2] (v1 <= x <= v2).  The boundaries v1 and v2
     can be given in either order.
 
@@ -948,9 +961,10 @@
     return masked_where(condition, x, copy=copy)
 
 def masked_outside(x, v1, v2, copy=True):
-    """Shortcut to masked_where, where condition is True for x outside
-    the interval [v1,v2] (x < v1)|(x > v2).  The boundaries v1 and v2
-    can be given in either order.
+    """
+    Shortcut to ``masked_where``, where ``condition`` is True for x outside
+    the interval [v1,v2] (x < v1)|(x > v2).
+    The boundaries v1 and v2 can be given in either order.
 
     Notes
     -----
@@ -965,10 +979,11 @@
 
 #
 def masked_object(x, value, copy=True, shrink=True):
-    """Mask the array x where the data are exactly equal to value.
+    """
+    Mask the array ``x`` where the data are exactly equal to value.
 
     This function is suitable only for object arrays: for floating
-    point, please use ``masked_values`` instead.
+    point, please use :func:`masked_values` instead.
 
     Parameters
     ----------
@@ -992,13 +1007,14 @@
     return masked_array(x, mask=mask, copy=copy, fill_value=value)
 
 def masked_values(x, value, rtol=1.e-5, atol=1.e-8, copy=True, shrink=True):
-    """Mask the array x where the data are approximately equal in
+    """
+    Mask the array x where the data are approximately equal in
     value, i.e.
 
     (abs(x - value) <= atol+rtol*abs(value))
 
     Suitable only for floating points. For integers, please use
-    ``masked_equal``.  The mask is set to nomask if posible.
+    :func:`masked_equal`.  The mask is set to ``nomask`` if posible.
 
     Parameters
     ----------
@@ -1028,8 +1044,9 @@
     return masked_array(xnew, mask=mask, copy=copy, fill_value=value)
 
 def masked_invalid(a, copy=True):
-    """Mask the array for invalid values (nans or infs).  Any
-    preexisting mask is conserved.
+    """
+    Mask the array for invalid values (NaNs or infs).
+    Any preexisting mask is conserved.
 
     """
     a = np.array(a, copy=copy, subok=True)
@@ -1048,8 +1065,8 @@
 #---- --- Printing options ---
 #####--------------------------------------------------------------------------
 class _MaskedPrintOption:
-    """Handle the string used to represent missing data in a masked
-    array.
+    """
+    Handle the string used to represent missing data in a masked array.
 
     """
     def __init__ (self, display):
@@ -1087,7 +1104,8 @@
 
 #...............................................................................
 class _arraymethod(object):
-    """Define a wrapper for basic array methods.
+    """
+    Define a wrapper for basic array methods.
 
     Upon call, returns a masked array, where the new _data array is
     the output of the corresponding method called on the original
@@ -1170,7 +1188,8 @@
 
 
 class MaskedArray(ndarray):
-    """Arrays with possibly masked values.  Masked values of True
+    """
+    Arrays with possibly masked values.  Masked values of True
     exclude the corresponding element from any computation.
 
     Construction:
@@ -3839,7 +3858,6 @@
 
 
 def inner(a, b):
-    "maskedarray version of the numpy function."
     fa = filled(a, 0)
     fb = filled(b, 0)
     if len(fa.shape) == 0:
@@ -3847,7 +3865,12 @@
     if len(fb.shape) == 0:
         fb.shape = (1,)
     return np.inner(fa, fb).view(MaskedArray)
+<<<<<<< .mine
+inner.__doc__ = doc_note(np.inner.__doc__, 
+                         "Masked values are replaced by 0.")
+=======
 
+>>>>>>> .r5706
 innerproduct = inner
 if np.inner.__doc__ is not None :
     notes = doc_note("Masked values are replaced by 0.")
@@ -3866,7 +3889,12 @@
     mb = getmaskarray(b)
     m = make_mask(1-np.outer(1-ma, 1-mb), copy=0)
     return masked_array(d, mask=m)
+<<<<<<< .mine
+outer.__doc__ = doc_note(np.outer.__doc__,
+                         "Masked values are replaced by 0.")
+=======
 
+>>>>>>> .r5706
 outerproduct = outer
 if np.outer.__doc__ is not None :
     notes = doc_note("Masked values are replaced by 0.")

Modified: trunk/numpy/ma/extras.py
===================================================================
--- trunk/numpy/ma/extras.py	2008-08-26 19:32:02 UTC (rev 5706)
+++ trunk/numpy/ma/extras.py	2008-08-26 22:19:44 UTC (rev 5707)
@@ -95,15 +95,21 @@
 #####--------------------------------------------------------------------------
 class _fromnxfunction:
     """Defines a wrapper to adapt numpy functions to masked arrays."""
+
     def __init__(self, funcname):
         self.__name__ = funcname
         self.__doc__ = self.getdoc()
 
     def getdoc(self):
         "Retrieves the __doc__ string from the function."
-        return getattr(np, self.__name__).__doc__ +\
-            "*Notes*:\n    (The function is applied to both the _data and the _mask, if any.)"
+        inidoc = getattr(np, self.__name__).__doc__
+        if inidoc:
+            locdoc = "Notes\n-----\nThe function is applied to both the _data"\
+                     " and the _mask, if any."
+            return '\n'.join((inidoc, locdoc))
+        return
 
+
     def __call__(self, *args, **params):
         func = getattr(np, self.__name__)
         if len(args)==1:



More information about the Numpy-svn mailing list