Skip to content

Expose validation errors #402

Open
Open

Description

It would be useful if the validation errors (SchemaError and ValidationError) would be exported so that the errors could be referenced, e.g. with pytest.raises((dy.SchemaError, dy.ValidationError)):.

Activity

  1. borchero commented on Sep 10, 2026

    @borchero
    Member

    If you want to persist the errors, isn't it an option to use Schema.filter instead of Schema.validate?

  2. datenzauberai commented on Sep 11, 2026

    @datenzauberai
    Author

    I'm not sure what you mean by persisting the errors. Maybe my description was lacking...

    Right now the errors are not exposed in the public top-level API. Although they are not marked as private, it feels a bit hacky to import them from the exception module.

    Today:

    import dataframely as dy
    from dataframely.exc import SchemaError
    
    try:
        MySchema.validate(df)
    except SchemaError as exc:
        print(exc)

    Technically you can reference the exception module exc at runtime, but linters will complain that exc is an unknown attribute:

    import dataframely as dy
    
    try:
        MySchema.validate(df)
    # works but linter will complain
    except dy.exc.SchemaError as exc:
        print(exc)

    That could be fixed by exposing the exception module, but I think it would be even better to have the exceptions exposed at the top-level (e.g. Patito does that https://patito.readthedocs.io/en/latest/api/patito/DataFrame/validate.html):

    import dataframely as dy
    
    try:
        MySchema.validate(df)
    except dy.SchemaError as exc:
        print(exc)
  3. changed the title [-]Export validation errors[/-] [+]Expose validation errors[/+] on Sep 11, 2026
  4. borchero commented on Sep 14, 2026

    @borchero
    Member

    Got it, sorry! 😅

    In the tests, we commonly do

    from dataframely.exc import ...

    but you could also just do something like

    import dataframely.exc as dyexc

    for now. I think it would be fair to expose these errors on the top-level though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions