#NEWLINE# def crosscat_value_to_code( bdb , generator_id , M_c , colno , value ) : #NEWLINE# #INDENT# stattype = core . bayesdb_generator_column_stattype ( bdb , generator_id , colno ) #NEWLINE# if ( stattype == 'categorical' ) : #NEWLINE# #INDENT# if ( value is None ) : #NEWLINE# #INDENT# return float ( 'NaN' ) #NEWLINE# #UNINDENT# cc_colno = crosscat_cc_colno ( bdb , generator_id , colno ) #NEWLINE# key = unicode ( M_c ) #NEWLINE# code = M_c [ 'column_metadata' ] [ cc_colno ] [ 'code_to_value' ] [ key ] #NEWLINE# return float ( code ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( stattype in ( 'cyclic' , 'numerical' ) ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# return float ( value ) #NEWLINE# #UNINDENT# except ( ValueError , TypeError ) : #NEWLINE# #INDENT# return float ( 'NaN' ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# raise KeyError