Comments (9)
Yes, thanks for reporting this! I also discovered this bug recently, and unfortunately this is a miss on my part... the number_type
parameter is not passed on to the natsort_key
that is recursively called to sort the lists of lists. This will be fixed in the next release.
As a temporary workaround, you could try something like this:
from operator import itemgetter
versorted(your_list, key=itemgetter(1))
Sorry about the inconvenience.
from natsort.
Thanks for the solution! :)
from natsort.
No problem! I will leave this issue open until I make the commit that fixes this bug.
from natsort.
Hi Seth,
As an FYI, the fix you provided works when the the elements before the versioned values are the same but breaks down otherwise. Please see the example below:
>>> l = [('a', '1.10 '), ('a', '1.1 '), ('b', '1.1.2 '), ('a', '1.2 ')]
>>> versorted(l, key=itemgetter(1))
[('a', '1.1 '), ('b', '1.1.2 '), ('a', '1.2 '), ('a', '1.10 ')]
whereas the expected output would be:
[('a', '1.1 '), ('a', '1.2 '), ('a', '1.10 '), ('b', '1.1.2 ')]
Hope that helps!
Thanks!
from natsort.
Yes, I am aware of that. In the data set you initially gave, all the first elements were 'a' so it worked; I assumed that what you gave as an example was representative of your actual data. You will need to wait for the update to get the new data set to sort properly. I plan to release this within a week.
from natsort.
The official release is not yet completed, but you can check out the development branch to get the functionality you require (don't worry, it passes all unit tests). Specifically, the bug was fixed in commit eb08fe5.
from natsort.
Thanks! Will try it out.
from natsort.
This has been released now in version 3.4.0.
from natsort.
Hello from the future. versorted
is now depreciated and natsorted
should be preferred as it now handles versions correctly by default.
from natsort.
Related Issues (20)
- Can't use natsort_keygen() as key for sorting DataFrame with MultiIndex in pandas HOT 3
- Some values don't sort in a consistent order HOT 3
- Set which OS to sort by in `os_sorted` HOT 8
- Paths should be sorted like strings HOT 6
- Loosen types and type checking
- Sorting a list of dictionaries when the sort field might or might not have a number HOT 2
- Improve os_sorted performance by avoiding `Path` roundtrips HOT 1
- add a mode for hexadecimal numbers HOT 7
- 1 test fails HOT 5
- RFE: drop use `m2r2` module HOT 8
- Sorting income category with both string and num HOT 1
- compatibility with GNU coreutils sort -n (numeric sort) HOT 14
- 'os_sorted' sorts files with spaces in names not as in Windows Explorer HOT 2
- not consistent with behavior of windows chinese edition HOT 1
- `cmp_to_key` gives an error and I don't know if this is a bug or just not supported HOT 3
- wiki pages so huge that they are not loaded properly HOT 2
- Error while sorting dates if `NaT` HOT 3
- Unexpected natural sort when sorting multi-dimensional arrays or `pandas.DataFrame` HOT 14
- Support Python 3.12 HOT 2
- Character based sorting HOT 14
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from natsort.