numpy/numpy — pull request #5099 by perimosocordiae (2014-09-22 18:32:32+00:00)
Title: BUG: np.unique with chararray + inverse_index

The call to `empty_like` was trying to use the `chararray` subclass, which doesn't support the `np.intp` dtype.

```
In [16]: foo = np.chararray(5)

In [17]: np.unique(foo)
Out[17]:
chararray([''],
dtype='|S1')

In [18]: np.unique(foo, return_inverse=True)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
in ()
----> 1 np.unique(foo, return_inverse=True)

/usr/local/lib/python2.7/dist-packages/numpy/lib/arraysetops.pyc in unique(ar, return_index, return_inverse, return_counts)
205 if return_inverse:
206 iflag = np.cumsum(flag) - 1
--> 207 inv_idx = np.empty_like(ar, dtype=np.intp)
208 inv_idx[perm] = iflag
209 ret += (inv_idx,)

/usr/local/lib/python2.7/dist-packages/numpy/core/defchararray.pyc in __array_finalize__(self, obj)
1846 # The b is a special case because it is used for reconstructing.
1847 if not _globalvar and self.dtype.char not in 'SUbc':
-> 1848 raise ValueError("Can only create a chararray from string data.")
1849
1850 def __getitem__(self, obj):

ValueError: Can only create a chararray from string data.
```