from utilities import column_population, row_population
import csv


def data_from_csv(fp):
    """Read and convert a csv file to JSON format using the csv library
    :param fp: File pointer object
    :return: tuple of columns and rows
    """

    with open(fp.name) as infile:
        dialect = csv.Sniffer().sniff(infile.read(1024))
        infile.seek(0)
        # TODO(asmacdo) Nice way of displaying if there is no header
        # has_header = csv.Sniffer().has_header(infile.read())
        # infile.seek(0)
        reader = csv.reader(infile, dialect)
        data = [row for row in reader]

    columns = column_population(data[0])
    rows = row_population(data[1:], data[0])

    return columns, rows

@@ -244,46 +244,8 @@
 %22%22%0A%0A
-    with open(fp.name) as infile:%0A    
     
@@ -274,22 +274,20 @@
 ).sniff(
-infile
+(fp)
 .read(10
@@ -299,18 +299,10 @@
     
-    infile
+fp
 .see
@@ -302,28 +302,24 @@
  fp.seek(0)%0A
-    
     # TODO(a
@@ -375,20 +375,16 @@
 der%0A    
-  
-  
 # has_he
@@ -430,20 +430,16 @@
 read())%0A
-    
     # in
@@ -451,20 +451,16 @@
 seek(0)%0A
-    
     read
@@ -475,22 +475,18 @@
 .reader(
-infile
+fp
 , dialec
@@ -488,20 +488,16 @@
 ialect)%0A
-    
     data

remove redundant file open