diff options
author | Seth M Morton <seth.m.morton@gmail.com> | 2014-05-07 19:54:01 -0700 |
---|---|---|
committer | Seth M Morton <seth.m.morton@gmail.com> | 2014-05-07 19:54:01 -0700 |
commit | e69383f14cc24eff632d3054545fe9c3e3e57445 (patch) | |
tree | 03e8222b6676985f65807a88e2ed07d5912cddb4 | |
parent | a15deceb7202c5642e1749b0ed875065771b618a (diff) | |
parent | 53b0f8df07fffdafd37729df1cc9bd4561a9af75 (diff) | |
download | natsort-e69383f14cc24eff632d3054545fe9c3e3e57445.tar.gz |
Merge branch 'develop'3.2.0
-rw-r--r-- | MANIFEST.in | 3 | ||||
-rw-r--r-- | README.rst | 53 | ||||
-rw-r--r-- | natsort/_version.py | 2 | ||||
-rw-r--r-- | natsort/natsort.py | 25 |
4 files changed, 52 insertions, 31 deletions
diff --git a/MANIFEST.in b/MANIFEST.in index d7a368c..40fc99e 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -6,4 +6,5 @@ include natsort/__main__.py include natsort/__init__.py include natsort/py23compat.py include setup.py -include setup.cfg
\ No newline at end of file +include setup.cfg +prune natsort/__pycache__ @@ -2,7 +2,7 @@ natsort ======= Natural sorting for python. ``natsort`` requires python version 2.6 or greater -(this includes python 3.x). To run version 2.6, 3.1, or 3.2 the +(this includes python 3.x). To run version 2.6, 3.0, or 3.1 the `argparse <https://pypi.python.org/pypi/argparse>`_ module is required. ``natsort`` comes with a shell script that is described below. You can @@ -24,7 +24,7 @@ expect:: ['a1', 'a10', 'a2', 'a4', 'a9'] Notice that it has the order ('1', '10', '2') - this is because the list is -being sorted in lexicographically order, which sorts numbers like you would +being sorted in lexicographical order, which sorts numbers like you would letters (i.e. 'a', 'at', 'b'). It would be better if you had a sorting algorithm that recognized numbers as numbers and treated them like numbers, not letters. @@ -48,9 +48,9 @@ Using ``natsort`` is simple:: You can also mix and match ``int``, ``float``, and ``str`` (or ``unicode``) types when you sort:: - >>> a = ['4.5', 6, 2.3, '5'] + >>> a = ['4.5', 6, 2.3, '5', 'a'] >>> natsorted(a) - [2.3, '4.5', '5', 6] + [2.3, '4.5', '5', 6, 'a'] >>> # On Python 2, sorted(a) would return [2.3, 6, '4.5', '5'] >>> # On Python 3, sorted(a) would raise an "unorderable types" TypeError @@ -334,17 +334,26 @@ Seth M. Morton History ------- +05-07-2014 v. 3.2.0 +''''''''''''''''''' + + - "Fixed" unorderable types issue on Python 3.x with a workaround that + attempts to replicate the Python 2.x behavior by putting all the numbers + (or strings that begin with numbers) first. + - Now explicitly excluding __pycache__ from releases by adding a prune statement + to MANIFEST.in. + 05-05-2014 v. 3.1.2 ''''''''''''''''''' - - Added setup.cfg to support universal wheels - - Added Python 3.0 and Python 3.1 as requiring the argparse module + - Added setup.cfg to support universal wheels. + - Added Python 3.0 and Python 3.1 as requiring the argparse module. 03-01-2014 v. 3.1.1 ''''''''''''''''''' - - Added ability to sort lists of lists - - Cleaned up import statements + - Added ability to sort lists of lists. + - Cleaned up import statements. 01-20-2014 v. 3.1.0 ''''''''''''''''''' @@ -369,9 +378,9 @@ History 10-01-2013 v. 3.0.2 ''''''''''''''''''' - - Made float, int, and digit searching algorithms all share the same base function - - Fixed some outdated comments - - Made the ``__version__`` variable available when importing the module + - Made float, int, and digit searching algorithms all share the same base function. + - Fixed some outdated comments. + - Made the ``__version__`` variable available when importing the module. 8-15-2013 v. 3.0.1 '''''''''''''''''' @@ -398,29 +407,29 @@ History 12-5-2012 v. 2.1.0 '''''''''''''''''' - - Reorganized package + - Reorganized package. - Now using a platform independent shell script generator (entry_points - from distribute) + from distribute). - Can now execute natsort from command line with ``python -m natsort`` - as well + as well. 11-30-2012 v. 2.0.2 ''''''''''''''''''' - - Added the use_2to3 option to setup.py - - Added distribute_setup.py to the distribution - - Added dependency to the argparse module (for python2.6) + - Added the use_2to3 option to setup.py. + - Added distribute_setup.py to the distribution. + - Added dependency to the argparse module (for python2.6). 11-21-2012 v. 2.0.1 ''''''''''''''''''' - - Reorganized directory structure - - Added tests into the natsort.py file iteself + - Reorganized directory structure. + - Added tests into the natsort.py file iteself. 11-16-2012, v. 2.0.0 '''''''''''''''''''' - Updated sorting algorithm to support floats (including exponentials) and - basic version number support - - Added better README documentation - - Added doctests + basic version number support. + - Added better README documentation. + - Added doctests. diff --git a/natsort/_version.py b/natsort/_version.py index 511b39b..253b833 100644 --- a/natsort/_version.py +++ b/natsort/_version.py @@ -1,4 +1,4 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -__version__ = '3.1.2' +__version__ = '3.2.0' diff --git a/natsort/natsort.py b/natsort/natsort.py index 90d197c..1d2d2d0 100644 --- a/natsort/natsort.py +++ b/natsort/natsort.py @@ -49,7 +49,7 @@ You can mix types with natsorted. This can get around the new 'unorderable types' issue with Python 3. >>> import sys - >>> a = [6, 4.5, '7', u'2.5'] + >>> a = [6, 4.5, '7', u'2.5', 'a'] >>> if sys.version[0] == '3': # Python 3 ... try: ... sorted(a) @@ -57,14 +57,14 @@ You can mix types with natsorted. This can get around the new ... print(e) ... else: # Python 2 ... # This will get the doctest to work properly while illustrating the point - ... if sorted(a) == [4.5, 6, u'2.5', '7']: + ... if sorted(a) == [4.5, 6, u'2.5', '7', 'a']: ... print('unorderable types: str() < float()') ... unorderable types: str() < float() >>> natsorted(a) - [{u}'2.5', 4.5, 6, {u}'7'] + [{u}'2.5', 4.5, 6, {u}'7', {u}'a'] -Natsort will recursively descend into lists of lists so you can sort by the sublist contents. +natsort will recursively descend into lists of lists so you can sort by the sublist contents. >>> data = [['a1', 'a5'], ['a1', 'a40'], ['a10', 'a1'], ['a2', 'a5']] >>> sorted(data) @@ -142,7 +142,12 @@ def _number_finder(s, regex, numconv): except ValueError: pass - return s + # If the list begins with a number, lead with an empty string. + # This is used to get around the "unorderable types" issue. + if not isinstance(s[0], py23_basestring): + return [''] + s + else: + return s @u_format @@ -197,10 +202,16 @@ def natsort_key(s, number_type=float, signed=True, exp=True): >>> natsort_key(('a1', 'a10')) (({u}'a', 1.0), ({u}'a', 10.0)) + Strings that lead with a number get an empty string at the front of the tuple. + This is designed to get around the "unorderable types" issue. + + >>> natsort_key(('15a', '6')) + (({u}'', 15.0, {u}'a'), ({u}'', 6.0)) + You can give numbers, too. >>> natsort_key(10) - (10,) + ({u}'', 10) """ @@ -209,7 +220,7 @@ def natsort_key(s, number_type=float, signed=True, exp=True): if hasattr(s, '__getitem__'): return tuple(natsort_key(x) for x in s) else: - return (s,) + return ('', s,) # Convert to the proper tuple and return inp_options = (number_type, signed, exp) |