#NEWLINE# def run( self , rows , column_names ) : #NEWLINE# #INDENT# '\n        Apply type inference to the provided data and return an array of\n        column types.\n\n        :param rows:\n            The data as a sequence of any sequences: tuples, lists, etc.\n        ' #NEWLINE# num_columns = len ( column_names ) #NEWLINE# hypotheses = [ set ( self . _possible_types ) for i in range ( num_columns ) ] #NEWLINE# force_indices = [ ] #NEWLINE# for name in self . _force . keys ( ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# force_indices . append ( column_names . index ( name ) ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# raise ValueError ( ( '"%s" does not match the name of any column in this table.' % name ) ) #NEWLINE# #UNINDENT# #UNINDENT# if self . _limit : #NEWLINE# #INDENT# sample_rows = rows [ : self . _limit ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( self . _limit == 0 ) : #NEWLINE# #INDENT# text = Text ( ) #NEWLINE# return tuple ( ( [ text ] * num_columns ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# sample_rows = rows #NEWLINE# #UNINDENT# #UNINDENT# for row in sample_rows : #NEWLINE# #INDENT# for i in range ( num_columns ) : #NEWLINE# #INDENT# if ( i in force_indices ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# h = hypotheses [ i ] #NEWLINE# if ( len ( h ) == 1 ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# for column_type in copy ( h ) : #NEWLINE# #INDENT# if ( ( len ( row ) > i ) and ( not column_type . test ( row [ i ] ) ) ) : #NEWLINE# #INDENT# h . remove ( column_type ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# column_types = [ ] #NEWLINE# for i in range ( num_columns ) : #NEWLINE# #INDENT# if ( i in force_indices ) : #NEWLINE# #INDENT# column_types . append ( self . _force [ column_names [ i ] ] ) #NEWLINE# continue #NEWLINE# #UNINDENT# h = hypotheses [ i ] #NEWLINE# for t in self . _possible_types : #NEWLINE# #INDENT# if ( t in h ) : #NEWLINE# #INDENT# column_types . append ( t ) #NEWLINE# break #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return tuple ( column_types )