Validating a DataFrame against a Pydantic model

This works:

valid_instances = []
validation_exceptions = [] 
for row in df_in.itertuples(index=False):
    try:
        valid_instances.append(
            validity_class(
                **{
                    key: row[i]
                    for i, key in enumerate(validity_class.__
                }
            )
        )
    except ValidationError as ve:  # pylint: disable=invalid-name
        validation_exceptions.append(ve)
 

The main issue seems to be getting good validation error messages.

Leave a Reply

Your email address will not be published. Required fields are marked *

I accept that my given data and my IP address is sent to a server in the USA only for the purpose of spam prevention through the Akismet program.More information on Akismet and GDPR.