changeset 107:19a5c2fb52bb

add transpose functionality
author Jeff Hammel <k0scist@gmail.com>
date Sun, 15 Mar 2015 10:02:48 -0700
parents 895ad896023a
children bad50c6bb243
files numerics/bar.py numerics/convert.py numerics/manipulate.py numerics/read.py
diffstat 4 files changed, 13 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/numerics/bar.py	Sun Mar 15 09:54:13 2015 -0700
+++ b/numerics/bar.py	Sun Mar 15 10:02:48 2015 -0700
@@ -19,7 +19,7 @@
 from bokeh.plotting import *
 from collections import OrderedDict
 
-__all__ = ['bar_chart', 'main']
+__all__ = ['bar_chart', 'BarChartParser', 'main']
 
 def bar_chart(data, output, title=None):
     """create a bar chart"""
@@ -29,6 +29,7 @@
     bar.width(len(data)*50)
     bar.show()
 
+
 class BarChartParser(CSVParser):
     """command line options parser for bar charts"""
     # TODO: upstream to PlotParser
--- a/numerics/convert.py	Sun Mar 15 09:54:13 2015 -0700
+++ b/numerics/convert.py	Sun Mar 15 10:02:48 2015 -0700
@@ -11,7 +11,8 @@
 from .data import transpose
 from .read import read_csv, CSVParser
 
-__all__ = ['cast',
+__all__ = ['default_cast',
+           'cast',
            'float_or_orig',
            'main']
 
--- a/numerics/manipulate.py	Sun Mar 15 09:54:13 2015 -0700
+++ b/numerics/manipulate.py	Sun Mar 15 10:02:48 2015 -0700
@@ -37,4 +37,3 @@
 
 if __name__ == '__main__':
     main()
-
--- a/numerics/read.py	Sun Mar 15 09:54:13 2015 -0700
+++ b/numerics/read.py	Sun Mar 15 10:02:48 2015 -0700
@@ -12,6 +12,7 @@
 import csv
 import os
 import sys
+from .data import transpose
 from .write import CSVWriter
 
 # module globals
@@ -145,7 +146,7 @@
 
     def columns(self):
         """return columns vs `data`'s rows"""
-        raise NotImplementedError('TODO') # -> record TODO items
+        return transpose(self.read())
 
 
 def main(args=sys.argv[1:]):
@@ -153,6 +154,9 @@
 
     # parse command line options
     parser = CSVParser()
+    parser.add_argument('--transpose', dest='transpose',
+                        action='store_true', default=False,
+                        help="transpose columns and rows")
     options = parser.parse_args(args)
 
     if not options.csv:
@@ -160,7 +164,10 @@
         options.csv = [sys.stdin]
 
     # read CSV
-    data = parser.read()
+    if options.transpose:
+        data = parser.columns()
+    else:
+        data = parser.read()
 
     # write CSV
     writer = CSVWriter(options.output)