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

Add thousands separator support when LOCALE is enabled. #36

Closed
madphysicist opened this issue Apr 5, 2016 · 6 comments
Closed

Add thousands separator support when LOCALE is enabled. #36

madphysicist opened this issue Apr 5, 2016 · 6 comments
Assignees
Labels

Comments

@madphysicist
Copy link
Contributor

This issue was discovered when I tried to suggest natsort as the way to go for this Stack Overflow question: http://stackoverflow.com/q/36431810/2988730

I was trying to do the following based on the docs:

import natsort, locale
locale.setlocale(locale.LC_ALL, 'german')
mylist = ['23 text', '23.130', '12 text', '1.482 text', '3,25']
natsort.humansorted(mylist)

or alternatively

natsort.natsorted(mylist, alg=natsort.ns.LOCALE)

The result in both cases is

['1.482 text', '3,25', '12 text', '23.130', '23 text']

The result that the OP (correctly) expected is

['3,25', '12 text', '23 text', '1.482 text', '23.130']

It appears that natsort is not picking up the locale correctly?

I am using Red Hat Enterprise Linux Release 6.5 (64 bit) with anaconda. natsort 4.0.3 is running under Python 3.5.

Also, just to check that the locale is being set, I ran locale.localeconv after locale.setlocale(locale.LC_ALL, 'german'):

{'currency_symbol': 'EUR',
 'decimal_point': ',',
 'frac_digits': 2,
 'grouping': [3, 3, 0],
 'int_curr_symbol': 'EUR ',
 'int_frac_digits': 2,
 'mon_decimal_point': ',',
 'mon_grouping': [3, 3, 0],
 'mon_thousands_sep': '.',
 'n_cs_precedes': 0,
 'n_sep_by_space': 1,
 'n_sign_posn': 1,
 'negative_sign': '-',
 'p_cs_precedes': 0,
 'p_sep_by_space': 1,
 'p_sign_posn': 1,
 'positive_sign': '',
 'thousands_sep': '.'}
@SethMMorton
Copy link
Owner

Natsort currently does not support thousands separators. It does understand the difference in the decimal point, but that's not the issue here. The problem is that it is unclear in general if something is supposed to be a thousands separator or not. For example, if a user provides "14,57 x,y" they would not want it treated as the thousands separator.

I would be in support of adding a flag to enable this, but not turning it on by default as I would be afraid it would break other people's code.

@madphysicist
Copy link
Contributor Author

That makes sense. I will take a look.

@SethMMorton
Copy link
Owner

I am in the middle of refactoring natsort to make it easier to add new features. I will add this functionality after I have completed the refactor.

@SethMMorton SethMMorton self-assigned this Apr 22, 2016
@SethMMorton SethMMorton changed the title Locale not being handled correctly Add thousands separator support when LOCALE is enabled. May 5, 2016
SethMMorton added a commit that referenced this issue May 6, 2016
LOCALENUM is also now dependent on FLOAT.

Additionally, it was found that the broken locale problem extends
to the thousands separator character. A lookup table has been
implemented for locales with known problems.

This closes issue #36.
@SethMMorton
Copy link
Owner

OK, version 5.0.0 is released and this functionality is now part of the LOCALE option (and thus also the humansorted function).

Feel free to add natsort to that SO question if you want now 😄

@madphysicist
Copy link
Contributor Author

Thanks. I certainly will. This library deserves to have good publicity.

@SethMMorton
Copy link
Owner

Thanks, I appreciate that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants