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

Make sorting by unsigned integers the natsorted default? #20

Closed
SethMMorton opened this issue Feb 7, 2015 · 1 comment
Closed

Make sorting by unsigned integers the natsorted default? #20

SethMMorton opened this issue Feb 7, 2015 · 1 comment

Comments

@SethMMorton
Copy link
Owner

I am making the proposal to change the default sorting algorithm for natsorted starting with version 4.0.0. Currently, natsorted looks for any string of numbers that are valid input to the float function in a greedy way (for example, "number-1.402e10hello" would be split into ['number', -14020000000.0, 'hello']).

I have observed that this does not pass the "rule of least astonishment" for most users because it is easy to not recognize that '-' and '.' are actually valid parts of a number or that the algorithm would be accounting for signs and decimals, and thus users are surprised to see natsorted return results where "version2.10" < "version2.2" or "version-2.0" < "version-1.0". I have observed this in this Stack Overflow Question, this issue reported to natsort, and this python module that was created because natsorted did not meet their expectations and instead of filing a bug report attacked natsort in its documentation (the documentation was toned down in the 3rd commit).

My proposal would be to make the behavior of the current function versorted be the default behavior for natsorted, and make the current natsorted behavior belong to a new function (possibly called realnatsorted but I am open to suggestions). versorted would remain for backwards compatibility. A SIGNED attribute to the ns algorithm chooser class would have to be added. This would mean that natsorted would by default return results where "version2.2" < "version2.10" and "version-1.0" < "version-2.0" which I believe would meet most user's expectations.

I am polling the community to find out if I am correct in my assumption that people would expect natsorted to only look for digits and not '-' and '.' from a string, and if it would be worth it to modify the natsorted default behavior to provide less astonishment without breaking existing code too severely.

@SethMMorton SethMMorton changed the title Make sorting by unsigned integers the default? Make sorting by unsigned integers the natsorted default? Feb 7, 2015
@SethMMorton SethMMorton changed the title Make sorting by unsigned integers the natsorted default? Make sorting by unsigned integers the natsorted default? Feb 7, 2015
@SethMMorton
Copy link
Owner Author

As a side note, this deprecated #11.

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

1 participant