comparison numerics/manipulate.py @ 136:cffa11cb91a0

hook this up
author Jeff Hammel <k0scist@gmail.com>
date Tue, 17 Mar 2015 12:01:16 -0700
parents 12649a88545c
children
comparison
equal deleted inserted replaced
135:12649a88545c 136:cffa11cb91a0
10 import os 10 import os
11 import sys 11 import sys
12 from .convert import default_cast, cast_columns 12 from .convert import default_cast, cast_columns
13 from .data import transpose 13 from .data import transpose
14 from .read import CSVParser 14 from .read import CSVParser
15 from .sort import Sorter 15 from .sort import Sorter, sort_arg
16 16
17 # module globals 17 # module globals
18 __all__ = ['ManipulationParser', 'FloatParser', 'main'] 18 __all__ = ['ManipulationParser', 'FloatParser', 'main']
19 19
20 20
24 types = default_cast 24 types = default_cast
25 25
26 def __init__(self, **kwargs): 26 def __init__(self, **kwargs):
27 kwargs.setdefault('description', __doc__) 27 kwargs.setdefault('description', __doc__)
28 CSVParser.__init__(self, **kwargs) 28 CSVParser.__init__(self, **kwargs)
29 self.add_argument('--sort', dest='sort', nargs='+',
30 type=sort_arg,
31 help="column to sort by; will be reverse if prepended by '-'")
29 self.options = None 32 self.options = None
30 33
31 def typed_data(self): 34 def typed_data(self):
32 """return parsed and casted data""" 35 """return parsed and casted data"""
33 return cast_columns(self.columns(), self.types) 36 columns = cast_columns(self.columns(), self.types)
37
38 if self.options.sort:
39 # sort the data
40 sorter = Sorter(*self.options.sort)
41 rows = sorter(transpose(columns))
42
43 # re-transpose
44 columns = transpose(rows)
45
46 return columns
34 47
35 def process(self): 48 def process(self):
36 return transpose(self.typed_data()) 49 return transpose(self.typed_data())
37 50
38 51