summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSeth M Morton <seth.m.morton@gmail.com>2013-08-15 21:10:10 -0700
committerSeth M Morton <seth.m.morton@gmail.com>2013-08-15 21:10:10 -0700
commit55afe6e5ae034210d1bb17d64bd7f133f593f96d (patch)
treea18f21f69d61f894719fd96b8e05f34efcf2d4d4
parent282a7a371ff18a865fff8f49fadd8f0bb1449156 (diff)
downloadnatsort-3.0.1.tar.gz
Added unicode support, removed extra function.3.0.1
-rw-r--r--README.rst16
-rw-r--r--natsort/_version.py2
-rw-r--r--natsort/natsort.py37
3 files changed, 29 insertions, 26 deletions
diff --git a/README.rst b/README.rst
index 839731e..8cf043d 100644
--- a/README.rst
+++ b/README.rst
@@ -45,6 +45,15 @@ Using ``natsort`` is simple::
``natsort`` identifies the numbers and sorts them separately from letters.
+You can also mix and match ``int``, ``float``, ``str``, and ``unicode`` types
+when you sort::
+
+ >>> a = ['4.5', 6, 2.3, u'5']
+ >>> sorted(a)
+ [2.3, 6, '4.5', u'5']
+ >>> natsorted(a)
+ [2.3, '4.5', u'5', 6]
+
The sorting algorithms
''''''''''''''''''''''
@@ -280,6 +289,13 @@ Seth M. Morton
History
-------
+8-15-2013 v. 3.0.1
+''''''''''''''''''
+
+ - Added support for unicode strings.
+ - Removed extraneous ``string2int`` function.
+ - Fixed empty string removal function.
+
7-13-2013 v. 3.0.0
''''''''''''''''''
diff --git a/natsort/_version.py b/natsort/_version.py
index 4eb28e3..b7a5531 100644
--- a/natsort/_version.py
+++ b/natsort/_version.py
@@ -1 +1 @@
-__version__ = '3.0.0'
+__version__ = '3.0.1'
diff --git a/natsort/natsort.py b/natsort/natsort.py
index 4943534..ba9dc3b 100644
--- a/natsort/natsort.py
+++ b/natsort/natsort.py
@@ -42,6 +42,12 @@ See the README or the natsort homepage for more details.
>>> natsorted(a, number_type=None)
['version-1', 'version-2', 'version-4', 'version-20']
+ >>> a = [6, 4.5, '7', u'2.5']
+ >>> sorted(a)
+ [4.5, 6, u'2.5', '7']
+ >>> natsorted(a)
+ [u'2.5', 4.5, 6, '7']
+
"""
import re
@@ -55,26 +61,6 @@ digit_re = re.compile(r'(\d+)')
int_re = re.compile(r'([-+]?[0-9]+)')
-def string2int(string):
- """\
- Convert to integer if an integer string.
-
- >>> isinstance(string2int('2'), int)
- True
- >>> isinstance(string2int('a'), str)
- True
- >>> isinstance(string2int('2.0'), str)
- True
-
- """
- if not isinstance(string, str):
- return string
- try:
- return int(string)
- except ValueError:
- return string
-
-
def remove_empty(s):
"""\
Remove empty strings from a list.
@@ -84,10 +70,11 @@ def remove_empty(s):
['a', 2, 'b']
"""
- try:
- s.remove('')
- except ValueError:
- pass
+ while True:
+ try:
+ s.remove('')
+ except ValueError:
+ break
return s
@@ -209,7 +196,7 @@ def natsort_key(s, number_type=float):
"""
# If we are dealing with non-strings, return now
- if not isinstance(s, str):
+ if not isinstance(s, basestring):
return (s,)
# Convert to the proper tuple and return