#NEWLINE# def test_mode_choice_spec( ) : #NEWLINE# #INDENT# spec = pd . DataFrame ( { #NEWLINE# #INDENT# 'Alternative' : [ 'One' , 'One,Two' ] , #NEWLINE# 'Expression' : [ '1' , '$expr.format(var="bar")' ] , #NEWLINE# 'Work' : [ 'ivt' , 'ivt_lr' ] , #NEWLINE# #UNINDENT# } ) . set_index ( [ 'Expression' ] ) #NEWLINE# coeffs = pd . DataFrame ( { #NEWLINE# #INDENT# 'Work' : [ '.7' , 'ivt * .7 * COST' ] , #NEWLINE# #UNINDENT# } , index = [ 'ivt' , 'ivt_lr' ] ) #NEWLINE# settings = { #NEWLINE# #INDENT# 'CONSTANTS' : { #NEWLINE# #INDENT# 'COST' : 2.0 , #NEWLINE# #UNINDENT# } , #NEWLINE# 'VARIABLE_TEMPLATES' : { #NEWLINE# #INDENT# 'expr' : '@foo * {var}' , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } #NEWLINE# df = _mode_choice_spec ( spec , coeffs , spec ) #NEWLINE# pdt . assert_series_equal ( df . reset_index ( ) . Alternative , pd . Series ( [ 'One' , 'One' , 'Two' ] , index = [ 0 , 1 , 2 ] , name = 'Alternative' ) ) #NEWLINE# pdt . assert_series_equal ( df . reset_index ( ) . Rowid , pd . Series ( [ 0 , 1 , 1 ] , index = [ 0 , 1 , 2 ] , name = 'Rowid' ) ) #NEWLINE# pdt . assert_series_equal ( df . reset_index ( ) [ 'Work' ] , pd . Series ( [ 0.7 , 0.98 , 0.98 ] , index = [ 0 , 1 , 2 ] , name = 'Work' ) ) #NEWLINE# pdt . assert_series_equal ( df . reset_index ( ) [ 'Expression' ] , pd . Series ( [ '1' , '@foo * bar' , '@foo * bar' ] , index = [ 0 , 1 , 2 ] , name = 'Expression' ) )