Mercurial > hg > numerics
comparison numerics/manipulate.py @ 110:5790bcb30bd8
moar stubbin
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Sun, 15 Mar 2015 15:28:15 -0700 |
parents | bad50c6bb243 |
children | c4d26ef63d8e |
comparison
equal
deleted
inserted
replaced
109:fae24f57dcb1 | 110:5790bcb30bd8 |
---|---|
8 # imports | 8 # imports |
9 import argparse | 9 import argparse |
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 .read import CSVParser | 14 from .read import CSVParser |
14 | 15 |
15 # module globals | 16 # module globals |
16 __all__ = ['ManipulationParser', 'main'] | 17 __all__ = ['ManipulationParser', 'main'] |
17 here = os.path.dirname(os.path.realpath(__file__)) | 18 |
18 string = (str, unicode) | |
19 | 19 |
20 class ManipulationParser(CSVParser): | 20 class ManipulationParser(CSVParser): |
21 """CLI option parser for data manipulation""" | 21 """CLI option parser for data manipulation""" |
22 | 22 |
23 types = default_cast | 23 types = default_cast |
27 CSVParser.__init__(self, **kwargs) | 27 CSVParser.__init__(self, **kwargs) |
28 self.options = None | 28 self.options = None |
29 | 29 |
30 def typed_data(self): | 30 def typed_data(self): |
31 """return parsed and casted data""" | 31 """return parsed and casted data""" |
32 raise NotImplementedError('TODO') # -> record TODO items | 32 return cast_columns(self.columns(), self.types) |
33 | |
34 def process(self): | |
35 return transpose(self.typed_data()) | |
33 | 36 |
34 def main(args=sys.argv[1:]): | 37 def main(args=sys.argv[1:]): |
35 """CLI""" | 38 """CLI""" |
36 | 39 |
37 # parse command line options | 40 # parse command line options |
38 parser = ManipulationParser() | 41 parser = ManipulationParser() |
39 options = parser.parse_args(args) | 42 options = parser.parse_args(args) |
40 | 43 |
44 # write manipulated data | |
45 parser.write(parser.process()) | |
46 | |
41 if __name__ == '__main__': | 47 if __name__ == '__main__': |
42 main() | 48 main() |