Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

np.unique no longer works with fixed float and string arrays in Python 3 #5145

Closed
astrofrog opened this issue Oct 2, 2014 · 3 comments
Closed

Comments

@astrofrog
Copy link
Contributor

In Python 2, the following code used to work, but no longer in Python 3:

In [6]: x = np.array([1.1, 'a'], dtype=np.object)

In [7]: np.unique(x)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-7-9a478241c930> in <module>()
----> 1 np.unique(x)

/Users/tom/Library/Python/3.4/lib/python/site-packages/numpy/lib/arraysetops.py in unique(ar, return_index, return_inverse, return_counts)
    193         aux = ar[perm]
    194     else:
--> 195         ar.sort()
    196         aux = ar
    197     flag = np.concatenate(([True], aux[1:] != aux[:-1]))

TypeError: unorderable types: float() > str()

Is this intended behavior, and if so, are there any suggested alternatives in this situation?

@juliantaylor
Copy link
Contributor

its not specific to numpy, its normal python3 behaviour for objects:

In [1]: sorted([1.1, u'a'])
TypeError: unorderable types: str() < float()

@juliantaylor
Copy link
Contributor

hm we have a pr somewhere that uses hashes for unique of object arrays somewhere ..

@juliantaylor
Copy link
Contributor

hm no just an issue, #641
closing as duplicate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants