summaryrefslogtreecommitdiff
path: root/numpy/core/defchararray.py
diff options
context:
space:
mode:
authorErik M. Bray <embray@stsci.edu>2015-06-18 18:52:16 -0400
committerErik M. Bray <embray@stsci.edu>2015-06-22 18:14:41 -0400
commiteef0e0ead3107d45c940480a40f66b7077f190bb (patch)
tree1f1a3f29d1c931aa9b7b5211c88feafbcc679edd /numpy/core/defchararray.py
parenta580d6fb832ee1c571a60b104e44b6b21f3c2951 (diff)
downloadnumpy-eef0e0ead3107d45c940480a40f66b7077f190bb.tar.gz
BUG: Fixed slicing of chararrays on Python 3.
When taking a slice of a chararray it was calling the rstrip() method on the resulting slice, resulting in a new array rather than a view of the original. This was an unintended consequence of the sq_slice member of the tp_as_sequence mapping being ignored in Python 3, so that slice lookups go directly through __getitem__. Fix test_expandtabs to not make the assumption that rstrip() will be applied twice to a value when using T[x][y] style indexing.
Diffstat (limited to 'numpy/core/defchararray.py')
-rw-r--r--numpy/core/defchararray.py4
1 files changed, 3 insertions, 1 deletions
diff --git a/numpy/core/defchararray.py b/numpy/core/defchararray.py
index cc6cb5a38..92ea8209c 100644
--- a/numpy/core/defchararray.py
+++ b/numpy/core/defchararray.py
@@ -1849,12 +1849,14 @@ class chararray(ndarray):
def __getitem__(self, obj):
val = ndarray.__getitem__(self, obj)
- if issubclass(val.dtype.type, character) and not _len(val) == 0:
+
+ if isinstance(val, character):
temp = val.rstrip()
if _len(temp) == 0:
val = ''
else:
val = temp
+
return val
# IMPLEMENTATION NOTE: Most of the methods of this class are