typeddfs.utils.sort_utils
ο
Tools for sorting.
Module Contentsο
- class typeddfs.utils.sort_utils.SortUtilsο
- classmethod _ns_info_from_int_flag(cls, val: int) NatsortFlagsAndValue ο
- classmethod all_natsort_flags(cls) Mapping[str, int] ο
Returns all flags defined by natsort, including combined and default flags. Combined flags are, e.g.,
ns_enum.ns.REAL ns_enum.nsFLOAT | ns_enum.ns.SIGNED.
. Default flags are, e.g.,ns_enum.ns.UNSIGNED
.See also
std_natsort_flags()
- Returns
A mapping from flag name to int value
- classmethod core_natsort_flags(cls) Mapping[str, int] ο
Returns natsort flags that are not combinations or defaults.
See also
- Returns
A mapping from flag name to int value
- classmethod exact_natsort_alg(cls, flags: Union[None, int, Collection[Union[int, str]]]) NatsortFlagsAndValue ο
Gets the flag names and combined
alg=
argument for natsort.Examples
exact_natsort_alg({"REAL"}) == ({"FLOAT", "SIGNED"}, ns.FLOAT | ns.SIGNED)
exact_natsort_alg({}) == ({}, 0)
exact_natsort_alg(ns.LOWERCASEFIRST) == ({"LOWERCASEFIRST"}, ns.LOWERCASEFIRST)
exact_natsort_alg({"localenum", "numafter"})
== ({"LOCALENUM", "NUMAFTER"}, ns.LOCALENUM | ns.NUMAFTER)
- Parameters
flags β Can be either: - a single integer
alg
argument - a set of flag ints and/or names innatsort.ns
- Returns
A tuple of the set of flag names, and the corresponding input to
natsorted
Only uses standard flag names, never the βcombinedβ ones. (E.g.exact_natsort_alg({"REAL"})
will return({"FLOAT", "SIGNED"}, ns.FLOAT | ns.SIGNED)
.
- classmethod guess_natsort_alg(cls, dtype: Type[Any]) NatsortFlagsAndValue ο
Guesses a good natsorted flag for the dtype.
- Here are some specifics:
integers β INT and SIGNED
floating-point β FLOAT and SIGNED
strings β COMPATIBILITYNORMALIZE and GROUPLETTERS
datetime β GROUPLETTERS (only affects βZβ vs. βzβ; shouldnβt matter)
- Parameters
dtype β Probably from
pd.Series.dtype
- Returns
A tuple of (set of flags, int) β see
exact_natsort_alg()
- classmethod natsort(cls, lst: Iterable[T], dtype: Type[T], *, alg: Union[None, int, Set[str]] = None, reverse: bool = False) Sequence[T] ο
Perform a natural sort consistent with the type
dtype
. Uses natsort.See also
- Parameters
lst β A sequence of things to sort
dtype β The type; must be a subclass of each element in
lst
alg β A specific natsort algorithm or set of flags
reverse β Sort in reverse (e.g. Z to A or 9 to 1)