Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

BUG: fix regression for indexing chararrays with empty list. #247

Closed
wants to merge 1 commit into from
This page is out of date. Refresh to see the latest.
View
2  numpy/core/defchararray.py
@@ -1881,7 +1881,7 @@ def __array_finalize__(self, obj):
def __getitem__(self, obj):
val = ndarray.__getitem__(self, obj)
- if issubclass(val.dtype.type, character):
+ if issubclass(val.dtype.type, character) and not _len(val) == 0:
temp = val.rstrip()
if _len(temp) == 0:
val = ''
View
7 numpy/core/tests/test_defchararray.py
@@ -630,6 +630,13 @@ def test_rmod(self):
"non-string objects")
+def test_empty_indexing():
+ """Regression test for ticket 1948."""
+ # Check that indexing a chararray with an empty list/array returns an
+ # empty chararray instead of a chararray with a single empty string in it.
+ s = np.chararray((4,))
+ assert_(s[[]].size == 0)
+
if __name__ == "__main__":
run_module_suite()
Something went wrong with that request. Please try again.