[Numpy-svn] r2948 - in trunk/numpy: core oldnumeric

numpy-svn at scipy.org numpy-svn at scipy.org
Thu Aug 3 12:00:25 CDT 2006


Author: oliphant
Date: 2006-08-03 12:00:19 -0500 (Thu, 03 Aug 2006)
New Revision: 2948

Modified:
   trunk/numpy/core/defchararray.py
   trunk/numpy/oldnumeric/compat.py
Log:
Strip white-space on element retrieval

Modified: trunk/numpy/core/defchararray.py
===================================================================
--- trunk/numpy/core/defchararray.py	2006-08-03 13:19:50 UTC (rev 2947)
+++ trunk/numpy/core/defchararray.py	2006-08-03 17:00:19 UTC (rev 2948)
@@ -9,9 +9,10 @@
 _unicode = unicode
 
 # special sub-class for character arrays (string_ and unicode_)
-# This adds equality testing and methods of str and unicode types
+# This adds + and * operations and methods of str and unicode types
 #  which operate on an element-by-element basis
 
+# It also strips white-space on element retrieval
 
 class chararray(ndarray):
     def __new__(subtype, shape, itemsize=1, unicode=False, buffer=None,
@@ -40,36 +41,11 @@
         if not _globalvar and self.dtype.char not in 'SUb':
             raise ValueError, "Can only create a chararray from string data."
 
+    def __getitem__(self, obj):
+        val = ndarray.__getitem__(self, obj)
+        if isinstance(val, (string_, unicode_)):
+            return val.rstrip()
 
-##    def _richcmpfunc(self, other, op):
-##        b = broadcast(self, other)
-##        result = empty(b.shape, dtype=bool)
-##        res = result.flat
-##        for k, val in enumerate(b):
-##            r1 = val[0].rstrip('\x00')
-##            r2 = val[1]
-##            res[k] = eval("r1 %s r2" % op, {'r1':r1,'r2':r2})
-##        return result
-
-    # these have been moved to C
-##    def __eq__(self, other):
-##        return self._richcmpfunc(other, '==')
-
-##    def __ne__(self, other):
-##        return self._richcmpfunc(other, '!=')
-
-##    def __ge__(self, other):
-##        return self._richcmpfunc(other, '>=')
-
-##    def __le__(self, other):
-##        return self._richcmpfunc(other, '<=')
-
-##    def __gt__(self, other):
-##        return self._richcmpfunc(other, '>')
-
-##    def __lt__(self, other):
-##        return self._richcmpfunc(other, '<')
-
     def __add__(self, other):
         b = broadcast(self, other)
         arr = b.iters[1].base

Modified: trunk/numpy/oldnumeric/compat.py
===================================================================
--- trunk/numpy/oldnumeric/compat.py	2006-08-03 13:19:50 UTC (rev 2947)
+++ trunk/numpy/oldnumeric/compat.py	2006-08-03 17:00:19 UTC (rev 2948)
@@ -144,7 +144,6 @@
 innerproduct = deprecate(mu.inner, 'innerproduct', 'inner')
 
 
-
 def DumpArray(m, fp):
     m.dump(fp)
 



More information about the Numpy-svn mailing list