Code Monkey home page Code Monkey logo

Comments (9)

SethMMorton avatar SethMMorton commented on August 13, 2024

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.

sidhanti avatar sidhanti commented on August 13, 2024

Thanks for the solution! :)

from natsort.

SethMMorton avatar SethMMorton commented on August 13, 2024

No problem! I will leave this issue open until I make the commit that fixes this bug.

from natsort.

sidhanti avatar sidhanti commented on August 13, 2024

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.

SethMMorton avatar SethMMorton commented on August 13, 2024

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.

SethMMorton avatar SethMMorton commented on August 13, 2024

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.

sidhanti avatar sidhanti commented on August 13, 2024

Thanks! Will try it out.

from natsort.

SethMMorton avatar SethMMorton commented on August 13, 2024

This has been released now in version 3.4.0.

from natsort.

SethMMorton avatar SethMMorton commented on August 13, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.