changeset 55:ecaf1d4b1c2c

this should work now; it doesnt, but it should
author Jeff Hammel <k0scist@gmail.com>
date Tue, 20 Jan 2015 16:12:40 -0800
parents bbfe25d23a9f
children 06e487f90e05
files numerics/convert.py
diffstat 1 files changed, 19 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/numerics/convert.py	Tue Jan 20 15:54:06 2015 -0800
+++ b/numerics/convert.py	Tue Jan 20 16:12:40 2015 -0800
@@ -4,7 +4,9 @@
 convert between types
 """
 
+# imports
 import argparse
+import csv
 import sys
 from .data import transpose
 from .read import read_csv, CSVParser
@@ -30,6 +32,15 @@
 
 def column_type(values, types=default_cast):
     """determine the type of a column"""
+    for t in types:
+        for value in values:
+            try:
+                t(value)
+            except TypeError:
+                break
+        else:
+            return t
+
     raise NotImplementedError('TODO') # -> record TODO items
 
 def cast_column(values, to=default_cast):
@@ -48,10 +59,16 @@
     # read CSV file
     data = parser.read()
 
-    import pdb; pdb.set_trace()
+    # transpose
+    columns = transpose(data)
+
+    # get types
+    types = [column_type(column) for column in columns]
 
     # print type information
-    raise NotImplementedError('TODO') # -> record TODO items
+    writer = csv.writer(sys.stdout)
+    writer.writerow(types)
+
 
 if __name__ == '__main__':
     main()