diff options
author | Stefan van der Walt <stefan@sun.ac.za> | 2006-08-02 20:44:43 +0000 |
---|---|---|
committer | Stefan van der Walt <stefan@sun.ac.za> | 2006-08-02 20:44:43 +0000 |
commit | 33d3fde298fb6ba2da8087f0354f8b6ec9b0d056 (patch) | |
tree | 0e7bcb760e2827a0b1fb93271414b4b9b1de7c75 | |
parent | a2031b1c6bba80f83f996acddd7f3efa0fb93be7 (diff) | |
download | numpy-33d3fde298fb6ba2da8087f0354f8b6ec9b0d056.tar.gz |
Fix rstrip for character arrays (ticket #222).
-rw-r--r-- | numpy/core/defchararray.py | 3 | ||||
-rw-r--r-- | numpy/core/tests/test_regression.py | 7 |
2 files changed, 8 insertions, 2 deletions
diff --git a/numpy/core/defchararray.py b/numpy/core/defchararray.py index 9e9e78122..2ddd6f5bd 100644 --- a/numpy/core/defchararray.py +++ b/numpy/core/defchararray.py @@ -135,14 +135,13 @@ class chararray(ndarray): for k, val in enumerate(myiter): newval = [] for chk in val[1:]: - if chk.dtype is object_ and chk.item() is None: + if not chk or (chk.dtype is object_ and chk.item() is None): break newval.append(chk) newitem = getattr(val[0],name)(*newval) maxsize = max(len(newitem), maxsize) res[k] = newitem newarr = chararray(myiter.shape, maxsize, self.dtype is unicode_) - print res, maxsize newarr[:] = res return newarr diff --git a/numpy/core/tests/test_regression.py b/numpy/core/tests/test_regression.py index a6bf45067..0be4c8d6e 100644 --- a/numpy/core/tests/test_regression.py +++ b/numpy/core/tests/test_regression.py @@ -331,6 +331,13 @@ class test_regression(NumpyTestCase): def check_unique_zero_sized(self,level=rlevel): """Ticket #205""" assert_array_equal([], N.unique(N.array([]))) + + def check_chararray_rstrip(self,level=rlevel): + """Ticket #222""" + x = N.chararray((1,),5) + x[0] = 'a ' + x = x.rstrip() + assert_equal(x[0], 'a') if __name__ == "__main__": NumpyTest().run() |