changeset 136:cffa11cb91a0

hook this up
author Jeff Hammel <k0scist@gmail.com>
date Tue, 17 Mar 2015 12:01:16 -0700
parents 12649a88545c
children a4e6b6ad6907
files numerics/manipulate.py
diffstat 1 files changed, 15 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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())