summaryrefslogtreecommitdiff
path: root/natsort/ns_enum.py
diff options
context:
space:
mode:
authorSeth Morton <seth.m.morton@gmail.com>2023-02-27 00:22:59 -0800
committerSeth Morton <seth.m.morton@gmail.com>2023-02-27 00:34:55 -0800
commit50389e16d3aba5139890e14d57257320a9bc7e11 (patch)
treeae00d7e693c7534aa2cc61b044ceae8236e54edd /natsort/ns_enum.py
parentcf2a55daf7e74d177c95149da623172b1b6d93ae (diff)
downloadnatsort-50389e16d3aba5139890e14d57257320a9bc7e11.tar.gz
Add presort to natsorted and friends
This will sort the collection as strings before sorting with the natsort algorithm. This ensures that strings that are different but represent the same numerical value get sorted independent of input order.
Diffstat (limited to 'natsort/ns_enum.py')
-rw-r--r--natsort/ns_enum.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/natsort/ns_enum.py b/natsort/ns_enum.py
index c147909..02f970f 100644
--- a/natsort/ns_enum.py
+++ b/natsort/ns_enum.py
@@ -114,6 +114,14 @@ class ns(enum.IntEnum): # noqa: N801
treat these as +Infinity and place them after all the other numbers.
By default, an NaN be treated as -Infinity and be placed first.
Note that this ``None`` is treated like NaN internally.
+ PRESORT, PS
+ Sort the input as strings before sorting with the `nasort`
+ algorithm. This can help eliminate inconsistent sorting in cases
+ where two different strings represent the same number. For example,
+ "a1" and "a01" both are internally represented as ("a", "1), so
+ without `PRESORT` the order of these two values would depend on
+ the order they appeared in the input (because Python's `sorted`
+ is a stable sorting algorithm).
Notes
-----
@@ -143,6 +151,7 @@ class ns(enum.IntEnum): # noqa: N801
NANLAST = NL = 1 << next(_counter)
COMPATIBILITYNORMALIZE = CN = 1 << next(_counter)
NUMAFTER = NA = 1 << next(_counter)
+ PRESORT = PS = 1 << next(_counter)
# Following were previously options but are now defaults.
DEFAULT = 0