2323from great_expectations .data_context .types .resource_identifiers import ExpectationSuiteIdentifier
2424
2525from schematic .models .validate_attribute import GenerateError
26+ from schematic .schemas .generator import SchemaGenerator
2627from schematic .utils .validate_utils import rule_in_rule_list
2728
2829logger = logging .getLogger (__name__ )
@@ -159,7 +160,7 @@ def build_expectation_suite(self,):
159160 if validation_rules :
160161 #iterate through all validation rules for an attribute
161162 for rule in validation_rules :
162-
163+ base_rule = rule . split ( " " )[ 0 ]
163164
164165 #check if rule has an implemented expectation
165166 if rule_in_rule_list (rule ,self .unimplemented_expectations ):
@@ -169,8 +170,9 @@ def build_expectation_suite(self,):
169170 args ["column" ] = col
170171 args ["result_format" ] = "COMPLETE"
171172
173+
172174 #Validate num
173- if rule == 'num' :
175+ if base_rule == 'num' :
174176 args ["mostly" ]= 1.0
175177 args ["type_list" ]= ['int' ,'int64' , 'float' , 'float64' ]
176178 meta = {
@@ -182,7 +184,7 @@ def build_expectation_suite(self,):
182184 }
183185
184186 #Validate float
185- elif rule == 'float' :
187+ elif base_rule == 'float' :
186188 args ["mostly" ]= 1.0
187189 args ["type_list" ]= ['float' , 'float64' ]
188190 meta = {
@@ -194,7 +196,7 @@ def build_expectation_suite(self,):
194196 }
195197
196198 #Validate int
197- elif rule == 'int' :
199+ elif base_rule == 'int' :
198200 args ["mostly" ]= 1.0
199201 args ["type_list" ]= ['int' ,'int64' ]
200202 meta = {
@@ -206,7 +208,7 @@ def build_expectation_suite(self,):
206208 }
207209
208210 #Validate string
209- elif rule == 'str' :
211+ elif base_rule == 'str' :
210212 args ["mostly" ]= 1.0
211213 args ["type_" ]= 'str'
212214 meta = {
@@ -217,7 +219,7 @@ def build_expectation_suite(self,):
217219 "validation_rule" : rule
218220 }
219221
220- elif rule . startswith ("recommended" ):
222+ elif base_rule == ("recommended" ):
221223 args ["mostly" ]= 0.0000000001
222224 args ["regex_list" ]= ['^$' ]
223225 meta = {
@@ -228,7 +230,7 @@ def build_expectation_suite(self,):
228230 "validation_rule" : rule
229231 }
230232
231- elif rule . startswith ("protectAges" ):
233+ elif base_rule == ("protectAges" ):
232234 #Function to convert to different age limit formats
233235 min_age , max_age = self .get_age_limits ()
234236
@@ -243,7 +245,7 @@ def build_expectation_suite(self,):
243245 "validation_rule" : rule
244246 }
245247
246- elif rule . startswith ("unique" ):
248+ elif base_rule == ("unique" ):
247249 args ["mostly" ]= 1.0
248250 meta = {
249251 "notes" : {
@@ -253,7 +255,7 @@ def build_expectation_suite(self,):
253255 "validation_rule" : rule
254256 }
255257
256- elif rule . startswith ("inRange" ):
258+ elif base_rule == ("inRange" ):
257259 args ["mostly" ]= 1.0
258260 args ["min_value" ]= float (rule .split (" " )[1 ])
259261 args ["max_value" ]= float (rule .split (" " )[2 ])
@@ -350,7 +352,8 @@ def generate_errors(
350352 validation_results : Dict ,
351353 validation_types : Dict ,
352354 errors : List ,
353- warnings : List
355+ warnings : List ,
356+ sg : SchemaGenerator ,
354357 ):
355358 """
356359 Purpose:
@@ -407,45 +410,50 @@ def generate_errors(
407410 #call functions to generate error messages and add to error list
408411 if validation_types [rule .split (" " )[0 ]]['type' ]== 'type_validation' :
409412 for row , value in zip (indices ,values ):
410- errors .append (
411- GenerateError .generate_type_error (
413+ vr_errors , vr_warnings = GenerateError .generate_type_error (
412414 val_rule = rule ,
413415 row_num = row + 2 ,
414416 attribute_name = errColumn ,
415417 invalid_entry = value ,
418+ sg = sg ,
416419 )
417- )
420+ if vr_errors :
421+ errors .append (vr_errors )
422+ if vr_warnings :
423+ warnings .append (vr_warnings )
418424 elif validation_types [rule .split (" " )[0 ]]['type' ]== 'regex_validation' :
419425 expression = result_dict ['expectation_config' ]['kwargs' ]['regex' ]
420-
421426 for row , value in zip (indices ,values ):
422- errors .append (
423- GenerateError .generate_regex_error (
427+ vr_errors , vr_warnings = GenerateError .generate_regex_error (
424428 val_rule = rule ,
425429 reg_expression = expression ,
426430 row_num = row + 2 ,
427431 module_to_call = 'match' ,
428432 attribute_name = errColumn ,
429433 invalid_entry = value ,
434+ sg = sg ,
430435 )
431- )
436+ if vr_errors :
437+ errors .append (vr_errors )
438+ if vr_warnings :
439+ warnings .append (vr_warnings )
432440 elif validation_types [rule .split (" " )[0 ]]['type' ]== 'content_validation' :
433- content_errors , content_warnings = GenerateError .generate_content_error (
441+ vr_errors , vr_warnings = GenerateError .generate_content_error (
434442 val_rule = rule ,
435443 attribute_name = errColumn ,
436444 row_num = list (np .array (indices )+ 2 ),
437445 error_val = values ,
438446 sg = self .sg
439447 )
440- if content_errors :
441- errors .append (content_errors )
448+ if vr_errors :
449+ errors .append (vr_errors )
442450 if rule .startswith ('protectAges' ):
443- self .censor_ages (content_errors ,errColumn )
451+ self .censor_ages (vr_errors ,errColumn )
444452 pass
445- elif content_warnings :
446- warnings .append (content_warnings )
453+ if vr_warnings :
454+ warnings .append (vr_warnings )
447455 if rule .startswith ('protectAges' ):
448- self .censor_ages (content_warnings ,errColumn )
456+ self .censor_ages (vr_warnings ,errColumn )
449457 pass
450458
451459 return errors , warnings
0 commit comments