# HG changeset patch # User Jeff Hammel # Date 1426618876 25200 # Node ID cffa11cb91a076b11d74758b83b74df85fdf8517 # Parent 12649a88545ce9957c1de60edb6bf648e65340ec hook this up diff -r 12649a88545c -r cffa11cb91a0 numerics/manipulate.py --- a/numerics/manipulate.py Tue Mar 17 11:53:33 2015 -0700 +++ b/numerics/manipulate.py Tue Mar 17 12:01:16 2015 -0700 @@ -12,7 +12,7 @@ from .convert import default_cast, cast_columns from .data import transpose from .read import CSVParser -from .sort import Sorter +from .sort import Sorter, sort_arg # module globals __all__ = ['ManipulationParser', 'FloatParser', 'main'] @@ -26,11 +26,24 @@ def __init__(self, **kwargs): kwargs.setdefault('description', __doc__) CSVParser.__init__(self, **kwargs) + self.add_argument('--sort', dest='sort', nargs='+', + type=sort_arg, + help="column to sort by; will be reverse if prepended by '-'") self.options = None def typed_data(self): """return parsed and casted data""" - return cast_columns(self.columns(), self.types) + columns = cast_columns(self.columns(), self.types) + + if self.options.sort: + # sort the data + sorter = Sorter(*self.options.sort) + rows = sorter(transpose(columns)) + + # re-transpose + columns = transpose(rows) + + return columns def process(self): return transpose(self.typed_data())