def get_cols(self, lines): """Initialize Column objects from a multi-line ASCII header Parameters ---------- lines : `list` List of table lines """ re_name_def = re.compile("^\s*%\s+(?P<colname>\w+)") self.names = [] for line in lines: if not line.startswith('%'): break # End of header lines else: match = re_name_def.search(line) if match: self.names.append(match.group('colname')) if not self.names: raise core.InconsistentTableError( 'No column names found in Omega header') self.cols = [] for n in self.names: col = core.Column(name=n) self.cols.append(col)
def get_cols(self, lines): """Initialize Column objects from a multi-line ASCII header Parameters ---------- lines : `list` List of table lines """ re_name_def = re.compile(r'^\s*%\s+(?P<colname>\w+)') self.names = [] for line in lines: if not line: # ignore empty lines in header (windows) continue if not line.startswith('%'): # end of header lines break match = re_name_def.search(line) if match: self.names.append(match.group('colname')) if not self.names: raise core.InconsistentTableError( 'No column names found in Omega header') self.cols = [] # pylint: disable=attribute-defined-outside-init for name in self.names: col = core.Column(name=name) self.cols.append(col)
def get_cols(self, lines): """Initialize Column objects from a multi-line ASCII header Parameters ---------- lines : `list` List of table lines """ re_name_def = re.compile( r'^\s*#\s+' # whitespace and comment marker r'(?P<colnumber>[0-9]+)\s+-\s+' # number of column r'(?P<colname>(.*))' ) self.names = [] include_cuts = False for line in lines: if not line: # ignore empty lines in header (windows) continue if not line.startswith('# '): # end of header lines break if line.startswith('# -/+'): include_cuts = True else: match = re_name_def.search(line) if match: self.names.append(match.group('colname').rstrip()) if not self.names: raise core.InconsistentTableError( 'No column names found in cWB header') if include_cuts: self.cols = [ # pylint: disable=attribute-defined-outside-init core.Column(name='selection cut 1'), core.Column(name='selection cut 2'), ] else: self.cols = [] # pylint: disable=attribute-defined-outside-init for name in self.names: col = core.Column(name=name) self.cols.append(col)
def get_cols(self, lines): """Initialize Column objects from a multi-line ASCII header Parameters ---------- lines : `list` List of table lines """ re_name_def = re.compile( "^\s*#\s+" # whitespace and comment marker "(?P<colnumber>[0-9]+)\s+-\s+" # number of column "(?P<colname>(.*))" ) self.names = [] for line in lines: if not line.startswith('# '): break # End of header lines elif line.startswith('# -/+'): include_cuts = True else: match = re_name_def.search(line) if match: self.names.append(match.group('colname').rstrip()) if not self.names: raise core.InconsistentTableError( 'No column names found in cWB header') if include_cuts: self.cols = [ core.Column(name='selection cut 1'), core.Column(name='selection cut 2'), ] else: self.cols = [] for n in self.names: col = core.Column(name=n) self.cols.append(col)
def setup(self): self.lst = [] self.lst.append([random.randint(-500, 500) for i in range(1000)]) self.lst.append([random.random() * 500 - 500 for i in range(1000)]) self.lst.append([ ''.join([random.choice(uppercase) for j in range(6)]) for i in range(1000) ]) self.cols = [core.Column(str(i + 1)) for i in range(3)] for col, x in izip(self.cols, self.lst): col.data = x self.table_cols = [table.Column(x) for x in self.lst] self.outputter = core.TableOutputter() self.table = table.Table()
def setup(self): self.lines = [] options = [['a b c d'], ['a b c \\', 'd'], ['a b \\', 'c \\', 'd'], ['a b \\', 'c d'], ['a \\', 'b c \\', 'd']] for i in range(1000): self.lines.extend(options[i % 5]) options = ['"a\tbc\t\td"', 'ab cd', '\tab\t\tc\td', 'a \tb \tcd'] self.line = ''.join([options[i % 4] for i in range(1000)]) self.vals = [randword() for i in range(1000)] self.csv_line = ','.join([str(x) for x in self.vals]) lst = [] lst.append([random.randint(-500, 500) for i in range(1000)]) lst.append([random.random() * 500 - 500 for i in range(1000)]) lst.append([ ''.join([random.choice(uppercase) for j in range(6)]) for i in range(1000) ]) self.cols = [core.Column(str(i + 1)) for i in range(3)] for col, x in izip(self.cols, lst): col.str_vals = [str(s) for s in x]