@@ -528,12 +528,14 @@ def validate_datatype(validator, datatype, instance, schema):
528528 in_datatype , _ = numpy_dtype_to_asdf_datatype (array .dtype )
529529 else :
530530 msg = "Not an array"
531- raise ValidationError (msg )
531+ yield ValidationError (msg )
532+ return
532533 elif isinstance (instance , (np .ndarray , NDArrayType )):
533534 in_datatype , _ = numpy_dtype_to_asdf_datatype (instance .dtype )
534535 else :
535536 msg = "Not an array"
536- raise ValidationError (msg )
537+ yield ValidationError (msg )
538+ return
537539
538540 # We are only concerned with some fields from the datatype
539541 # object in the schema so if the schema datatype is structured
@@ -547,23 +549,28 @@ def validate_datatype(validator, datatype, instance, schema):
547549
548550 if schema .get ("exact_datatype" , False ):
549551 yield ValidationError (f"Expected datatype '{ datatype } ', got '{ in_datatype } '" )
552+ return
550553
551554 np_datatype = asdf_datatype_to_numpy_dtype (datatype )
552555 np_in_datatype = asdf_datatype_to_numpy_dtype (in_datatype )
553556
554557 if not np_datatype .fields :
555558 if np_in_datatype .fields :
556559 yield ValidationError (f"Expected scalar datatype '{ datatype } ', got '{ in_datatype } '" )
560+ return
557561
558562 if not np .can_cast (np_in_datatype , np_datatype , "safe" ):
559563 yield ValidationError (f"Can not safely cast from '{ in_datatype } ' to '{ datatype } ' " )
564+ return
560565
561566 else :
562567 if not np_in_datatype .fields :
563568 yield ValidationError (f"Expected structured datatype '{ datatype } ', got '{ in_datatype } '" )
569+ return
564570
565571 if len (np_in_datatype .fields ) != len (np_datatype .fields ):
566572 yield ValidationError (f"Mismatch in number of columns: Expected { len (datatype )} , got { len (in_datatype )} " )
573+ return
567574
568575 for i in range (len (np_datatype .fields )):
569576 in_type = np_in_datatype [i ]
@@ -574,3 +581,4 @@ def validate_datatype(validator, datatype, instance, schema):
574581 f"Expected { numpy_dtype_to_asdf_datatype (out_type )[0 ]} , "
575582 f"got { numpy_dtype_to_asdf_datatype (in_type )[0 ]} " ,
576583 )
584+ return
0 commit comments