-
Notifications
You must be signed in to change notification settings - Fork 52
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
Python3 "unorderable types" error with LOCALE and PyICU installed. #22
Comments
I don't get this behavior on my Python 3.4.3 installation with your example as-is, but if I change to If I do kf = natsort.natsort_keygen( alg = (natsort.ns.LOCALE | natsort.ns.TYPESAFE ) )
ll = ['0','Á','2',b'Z']
sorted(map(str, ll),key=kf) I don't get any errors. I'm a little bit confused about where Either way, I'll try and come up with a way to handle this gracefully internally to natsort. FYI: natsort returns a tuple for all inputs because it has to split the numbers from the strings, but keep them logically grouped together. An empty string is placed before numbers to avoid unorderable types errors (please see issue #7). Sorting tuples is well defined. A key can return anything as long as it is orderable, which does not seem to be the case if |
As a side note, the issue has nothing to do with the '2' to |
Thanks for clarifying the tuple issue. But something is not comparing between our test systems.
Comparison of tuples may be well defined but Python3 does not like comparing the bytes element of the 'A' tuple to the string element of the '2' tuple:
Perhaps the real problem is that kf('A')==> (bytevalue,). You indicate this is not expected? Under what circumstances might this happen? Could it be an unexpected artifact of running OSX10.10 with default Locale?
n.b. icu is installed per your recommendation. |
I think I see the origin of the mismatch problem. I'm at work on a linux machine without This does need to be fixed. Thanks for finding this bug. |
Check out version 3.5.4 on PyPI. It should solve the problem (your specific example is now in the unit tests). |
The test case is quite simple,
The issue seems to be that when the input key is numeric e.g. '2', the output of kf is ('',2), where the first element is the null string. When the input key is a letter, the output is e.g.
(b'*\x05 \x01E\x88\x01\x06\x00',)
where the first element is bytes.Frankly I don't understand how kf can return a tuple in any case, since docs for sorted() (and for SortedDict, which is where I actually hit this) seem to imply it should return a scalar item. But whatever -- if in the case of a number it returned
b''
instead of just''
I think all would be well. I believe this would be line 135 of utils.py?The text was updated successfully, but these errors were encountered: