diff options
author | Travis Oliphant <oliphant@enthought.com> | 2006-08-03 17:00:19 +0000 |
---|---|---|
committer | Travis Oliphant <oliphant@enthought.com> | 2006-08-03 17:00:19 +0000 |
commit | fad726e58b7eb8452712a79a3cd52aee510f1104 (patch) | |
tree | f4fe6b8a8c4f3e59e985b3dc6a35325ff8069997 /numpy/core/defchararray.py | |
parent | 77187d2372898d6c18129aba9d562450a1af3a2c (diff) | |
download | numpy-fad726e58b7eb8452712a79a3cd52aee510f1104.tar.gz |
Strip white-space on element retrieval
Diffstat (limited to 'numpy/core/defchararray.py')
-rw-r--r-- | numpy/core/defchararray.py | 36 |
1 files changed, 6 insertions, 30 deletions
diff --git a/numpy/core/defchararray.py b/numpy/core/defchararray.py index 2ddd6f5bd..23a2c9e98 100644 --- a/numpy/core/defchararray.py +++ b/numpy/core/defchararray.py @@ -9,9 +9,10 @@ _globalvar = 0 _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,35 +41,10 @@ class chararray(ndarray): if not _globalvar and self.dtype.char not in 'SUb': raise ValueError, "Can only create a chararray from string data." - -## 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 __getitem__(self, obj): + val = ndarray.__getitem__(self, obj) + if isinstance(val, (string_, unicode_)): + return val.rstrip() def __add__(self, other): b = broadcast(self, other) |