def _parse_data(cols, text): ''' Convert to all data to dictionary. Keys are column headers and values are 1D NumPy arrays ''' import re cs_regex = re.compile('\s+') cols = cs_regex.split(cols) lc = len(cols) data = [[] for dummy in cols] for t in text: r = cs_regex.split(t.strip()) lr = len(r) if lr > lc: print 'Long row!' lr = lc for i in range(lr): data[i].append(SRSLoader._parse_value(r[i])) if lr < lc: print 'Short row!' for i in range(lr, lc): data[i].append(0) from pycore import array as parray return [(c, parray(d)) for c, d in zip(cols, data)]
def _parse_data(cols, text, warn): ''' Convert to all data to dictionary. Keys are column headers and values are 1D NumPy arrays ''' import re cs_regex = re.compile('\s+') if cols is None: # use first line r = cs_regex.split(text[0].strip()) lc = len(r) from math import log10, ceil p = ceil(log10(lc)) fmt = 'col%%0%dd' % p cols = [ fmt % (i+1,) for i in range(lc) ] else: if cols.count('\t') > 0: # columns separated by tabs cols = cols.split('\t') else: cols = cs_regex.split(cols) lc = len(cols) data = [[] for dummy in cols] for t in text: r = cs_regex.split(t.strip()) lr = len(r) if lr > lc: if warn: print 'Long row!' lr = lc for i in range(lr): data[i].append(SRSLoader._parse_value(r[i])) if lr < lc: if warn: print 'Short row!' for i in range(lr, lc): data[i].append(0) from pycore import array as parray return [(c, parray(d)) for c, d in zip(cols, data)]
def _parse_data(cols, text, warn): ''' Convert to all data to dictionary. Keys are column headers and values are 1D NumPy arrays ''' import re cs_regex = re.compile('\s+') if cols is None: # use first line r = cs_regex.split(text[0].strip()) lc = len(r) cols = ["Column_%d" % (i + 1, ) for i in range(lc)] else: if cols.count('\t') > 0: # columns separated by tabs cols = cols.split('\t') else: cols = cs_regex.split(cols) lc = len(cols) data = [[] for dummy in cols] for t in text: r = cs_regex.split(t.strip()) lr = len(r) if lr > lc: if warn: print "Long row!" lr = lc for i in range(lr): data[i].append(SRSLoader._parse_value(r[i])) if lr < lc: if warn: print "Short row!" for i in range(lr, lc): data[i].append(0) from pycore import array as parray return [(c, parray(d)) for c, d in zip(cols, data)]