#NEWLINE# @ parameter_space ( seed_value = range ( 1 , 2 ) , normalizer_name_and_func = [ ( 'demean' , ( lambda row : ( row - nanmean ( row ) ) ) ) , ( 'zscore' , ( lambda row : ( ( row - nanmean ( row ) ) / nanstd ( row ) ) ) ) ] , add_nulls_to_factor = ( False , True ) ) #NEWLINE# def test_normalizations_randomized( self , seed_value , normalizer_name_and_func , add_nulls_to_factor ) : #NEWLINE# #INDENT# ( name , func ) = normalizer_name_and_func #NEWLINE# shape = ( 7 , 7 ) #NEWLINE# nomask = self . ones_mask ( shape = shape ) #NEWLINE# eyemask = self . eye_mask ( shape = shape ) #NEWLINE# eyemask90 = rot90 ( eyemask ) #NEWLINE# xmask = ( eyemask & eyemask90 ) #NEWLINE# factor_data = self . randn_data ( seed = seed_value , shape = shape ) #NEWLINE# if add_nulls_to_factor : #NEWLINE# #INDENT# factor_data = where ( eyemask , factor_data , nan ) #NEWLINE# #UNINDENT# classifier_data = ( ( self . arange_data ( shape = shape , dtype = int64_dtype ) + seed_value ) % 3 ) #NEWLINE# classifier_data_eyenulls = where ( eyemask , classifier_data , ( - 1 ) ) #NEWLINE# classifier_data_eyenulls90 = where ( eyemask90 , classifier_data , ( - 1 ) ) #NEWLINE# classifier_data_xnulls = where ( xmask , classifier_data , ( - 1 ) ) #NEWLINE# f = self . f #NEWLINE# c = C ( ) #NEWLINE# c_with_nulls = OtherC ( ) #NEWLINE# m = Mask ( ) #NEWLINE# method = getattr ( f , name ) #NEWLINE# terms = { #NEWLINE# #INDENT# 'vanilla' : method ( ) , #NEWLINE# 'masked' : method ( mask = m ) , #NEWLINE# 'grouped' : method ( groupby = c ) , #NEWLINE# 'grouped_with_nulls' : method ( groupby = c_with_nulls ) , #NEWLINE# 'both' : method ( mask = m , groupby = c ) , #NEWLINE# 'both_with_nulls' : method ( mask = m , groupby = c_with_nulls ) , #NEWLINE# #UNINDENT# } #NEWLINE# expected = { #NEWLINE# #INDENT# 'vanilla' : apply_along_axis ( func , 1 , factor_data ) , #NEWLINE# 'masked' : where ( eyemask , grouped_apply ( factor_data , eyemask , func ) , nan ) , #NEWLINE# 'grouped' : grouped_apply ( factor_data , classifier_data , func ) , #NEWLINE# 'grouped_with_nulls' : where ( eyemask90 , grouped_apply ( factor_data , classifier_data_eyenulls90 , func ) , nan ) , #NEWLINE# 'both' : where ( eyemask , grouped_apply ( factor_data , classifier_data_eyenulls , func ) , nan ) , #NEWLINE# 'both_with_nulls' : where ( xmask , grouped_apply ( factor_data , classifier_data_xnulls , func ) , nan ) , #NEWLINE# #UNINDENT# } #NEWLINE# self . check_terms ( terms = terms , expected = expected , initial_workspace = { #NEWLINE# #INDENT# f : factor_data , #NEWLINE# c : classifier_data , #NEWLINE# c_with_nulls : classifier_data_eyenulls90 , #NEWLINE# Mask ( ) : eyemask , #NEWLINE# #UNINDENT# } , mask = self . build_mask ( nomask ) )