#NEWLINE# def guess_column_types( path , dialect , sample_size , encoding = 'utf-8' ) : #NEWLINE# #INDENT# '\n    Guess column types based on a sample of data.\n    ' #NEWLINE# book = xlrd . open_workbook ( path , on_demand = True ) #NEWLINE# sheet = book . sheet_by_index ( 0 ) #NEWLINE# column_types = [ ] #NEWLINE# for i in range ( sheet . ncols ) : #NEWLINE# #INDENT# values = sheet . col_values ( i ) [ 1 : ( sample_size + 1 ) ] #NEWLINE# types = sheet . col_types ( i ) [ 1 : ( sample_size + 1 ) ] #NEWLINE# nominal_type = determine_column_type ( types ) #NEWLINE# if ( nominal_type == xlrd . biffh . XL_CELL_EMPTY ) : #NEWLINE# #INDENT# column_types . append ( None ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( nominal_type == xlrd . biffh . XL_CELL_TEXT ) : #NEWLINE# #INDENT# column_types . append ( unicode ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( nominal_type == xlrd . biffh . XL_CELL_NUMBER ) : #NEWLINE# #INDENT# column_types . append ( determine_number_type ( values ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( nominal_type == xlrd . biffh . XL_CELL_DATE ) : #NEWLINE# #INDENT# column_types . append ( determine_date_type ( values , datemode = book . datemode ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( nominal_type == xlrd . biffh . XL_CELL_BOOLEAN ) : #NEWLINE# #INDENT# column_types . append ( bool ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( nominal_type == xlrd . biffh . XL_CELL_ERROR ) : #NEWLINE# #INDENT# column_types . append ( unicode ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise TypeInferenceError ( ( _ ( 'Unknown column type found in xls file: %s' ) % nominal_type ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# return [ ( t . __name__ if t else None ) for t in column_types ]