summaryrefslogtreecommitdiff
path: root/numpy/lib
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/lib')
-rw-r--r--numpy/lib/arraysetops.py2
-rw-r--r--numpy/lib/tests/test_arraysetops.py6
2 files changed, 7 insertions, 1 deletions
diff --git a/numpy/lib/arraysetops.py b/numpy/lib/arraysetops.py
index bc80d0ecd..5c3b504de 100644
--- a/numpy/lib/arraysetops.py
+++ b/numpy/lib/arraysetops.py
@@ -204,7 +204,7 @@ def unique(ar, return_index=False, return_inverse=False, return_counts=False):
ret += (perm[flag],)
if return_inverse:
iflag = np.cumsum(flag) - 1
- inv_idx = np.empty_like(ar, dtype=np.intp)
+ inv_idx = np.empty(ar.shape, dtype=np.intp)
inv_idx[perm] = iflag
ret += (inv_idx,)
if return_counts:
diff --git a/numpy/lib/tests/test_arraysetops.py b/numpy/lib/tests/test_arraysetops.py
index e83f8552e..39196f4bc 100644
--- a/numpy/lib/tests/test_arraysetops.py
+++ b/numpy/lib/tests/test_arraysetops.py
@@ -109,6 +109,12 @@ class TestSetOps(TestCase):
assert_array_equal(a2, unq)
assert_array_equal(a2_inv, inv)
+ # test for chararrays with return_inverse (gh-5099)
+ a = np.chararray(5)
+ a[...] = ''
+ a2, a2_inv = np.unique(a, return_inverse=True)
+ assert_array_equal(a2_inv, np.zeros(5))
+
def test_intersect1d(self):
# unique inputs
a = np.array([5, 7, 1, 2])