Code Monkey home page Code Monkey logo

Comments (6)

SethMMorton avatar SethMMorton commented on August 13, 2024

Can you post the full traceback?

from natsort.

cristianocoelho avatar cristianocoelho commented on August 13, 2024

C:\Windows\System32>python
Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.

test = [('hi','1'), ('appe','2'), ('apple',3)]
from natsort import natsort_keygen, ns
test.sort(key = natsort_keygen(key=lambda e: (e[0],e[1]), alg=ns.IC))
Traceback (most recent call last):
File "", line 1, in
File "C:\Python275\lib\site-packages\natsort\natsort.py", line 390, in _natsor
t_key
val = lowercase(val)
File "C:\Python275\lib\site-packages\natsort\locale_help.py", line 79, in
lowercase = lambda x: x.lower()
AttributeError: 'tuple' object has no attribute 'lower'

Hope that example helps! I believe this wont only happen with tuples but with any other data type that is not a string.

from natsort.

SethMMorton avatar SethMMorton commented on August 13, 2024

This code is in a try: except: block that catches a TypeError. The idea is that the code would assume a string was given, and if not, go to the branch that handles tuples/lists. Clearly, I need to update this to catch an AttributeError as well since calling lower() on a tuple does not raise a TypeError.

from natsort.

cristianocoelho avatar cristianocoelho commented on August 13, 2024

Glad I could help! Your library is very useful :)

May I take this chance to ask a question, what is the performance
improvement when using fastnumbers library? I ask this because my proyect
is hosted on amazon elastic beanstalk which is a bit picky about installing
libraries, and fastnumbers needs some C code as well which would be
difficult to install on the cloud. So I was wondering if the performance
improvement is worth it or not.

On Thu, Sep 25, 2014 at 12:26 PM, Seth Morton [email protected]
wrote:

This code is in a try: except: block that catches a TypeError. The idea
is that the code would assume a string was given, and if not, go to the
branch that handles tuples/lists. Clearly, I need to update this to catch
an AttributeError as well.


Reply to this email directly or view it on GitHub
#15 (comment).

Cristiano Coelho

_DEVELOPER_Allied South American Professionals
8 de octubre 2323 Of. 1205 - CP 11200
Tel. (+598) 2 408 1699
[email protected] [email protected]
www.asapuruguay.com

from natsort.

SethMMorton avatar SethMMorton commented on August 13, 2024

You should see about 30% speed improvement in the case where your strings contain only numbers; put another way, it will increase the efficiency of the string to number conversion only. Of course, in real life you are doing other string manipulations that will cause slowdowns that shadow the speed improvements of the number conversion, so the true speed improvement is really dependent on the input data and the options you choose. I recommend installing locally and testing out with your actual data.

The C code shouldn't be a problem to install... it has no library dependencies (except for Python), so if your server has a C compiler that should be all you need.

from natsort.

SethMMorton avatar SethMMorton commented on August 13, 2024

Check out natsort version 3.5.1, which includes this bugfix.

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.