#NEWLINE# def _loadarff( ofile ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# ( rel , attr ) = read_header ( ofile ) #NEWLINE# #UNINDENT# except ValueError as e : #NEWLINE# #INDENT# msg = ( 'Error while parsing header, error was: ' + str ( e ) ) #NEWLINE# raise ParseArffError ( msg ) #NEWLINE# #UNINDENT# hasstr = False #NEWLINE# for ( name , value ) in attr : #NEWLINE# #INDENT# type = parse_type ( value ) #NEWLINE# if ( type == 'string' ) : #NEWLINE# #INDENT# hasstr = True #NEWLINE# #UNINDENT# #UNINDENT# meta = MetaData ( rel , attr ) #NEWLINE# acls2dtype = { #NEWLINE# #INDENT# 'real' : float , #NEWLINE# 'integer' : float , #NEWLINE# 'numeric' : float , #NEWLINE# #UNINDENT# } #NEWLINE# acls2conv = { #NEWLINE# #INDENT# 'real' : safe_float , #NEWLINE# 'integer' : safe_float , #NEWLINE# 'numeric' : safe_float , #NEWLINE# #UNINDENT# } #NEWLINE# descr = [ ] #NEWLINE# convertors = [ ] #NEWLINE# if ( not hasstr ) : #NEWLINE# #INDENT# for ( name , value ) in attr : #NEWLINE# #INDENT# type = parse_type ( value ) #NEWLINE# if ( type == 'date' ) : #NEWLINE# #INDENT# ( date_format , datetime_unit ) = get_date_format ( value ) #NEWLINE# descr . append ( ( name , ( 'datetime64[%s]' % datetime_unit ) ) ) #NEWLINE# convertors . append ( partial ( safe_date , date_format = date_format , datetime_unit = datetime_unit ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( type == 'nominal' ) : #NEWLINE# #INDENT# n = maxnomlen ( value ) #NEWLINE# descr . append ( ( name , ( 'S%d' % n ) ) ) #NEWLINE# pvalue = get_nom_val ( value ) #NEWLINE# convertors . append ( partial ( safe_nominal , pvalue = pvalue ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# descr . append ( ( name , acls2dtype [ type ] ) ) #NEWLINE# convertors . append ( safe_float ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# raise NotImplementedError ( 'String attributes not supported yet, sorry' ) #NEWLINE# #UNINDENT# ni = len ( convertors ) #NEWLINE# def generator( row_iter , delim = ',' ) : #NEWLINE# #INDENT# elems = list ( range ( ni ) ) #NEWLINE# for raw in row_iter : #NEWLINE# #INDENT# if ( r_comment . match ( raw ) or r_empty . match ( raw ) ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# row = raw . split ( delim ) #NEWLINE# ( yield tuple ( [ convertors [ i ] ( row [ i ] ) for i in elems ] ) ) #NEWLINE# #UNINDENT# #UNINDENT# a = generator ( ofile ) #NEWLINE# data = np . fromiter ( a , descr ) #NEWLINE# return ( data , meta )