Skip to content

Raise PrimaryKeyError instead of ValueError for primary key issues #16

Description

@NilsSeibertQC

Currently, a ValueError is raised when issues with the primary key are encountered. These issues are:

  • the primary key property not holding for the data
  • the specified columns not being present
  • an empty primary key being provided
  • no primary key at all.

A dedicated PrimaryKeyError would allow catching these issues specifically, instead of relying on the broad ValueError.

Activity

  1. MariusMerkleQC commented on Mar 16, 2026

    @MariusMerkleQC
    Collaborator

    Thanks for the suggestion! Could you share more about your use case? In particular, are there situations where you'd want to catch primary key errors programmatically rather than fixing the data or the key specification?

  2. NilsSeibertQC commented on Mar 19, 2026

    @NilsSeibertQC
    Author

    Of course, here are some more details: We programatically create comparison reports for many frames. We have a schema and thereby primary key assumption for each. But in case of recent schema changes, this assumption might not reflect the actual data. We want to include such PrimaryKeyErrors as information in the report, but want to fail on other errors. Validating our primary key assumption before using diffly duplicates work, which we would like to avoid.

  3. MariusMerkleQC commented on Mar 19, 2026

    @MariusMerkleQC
    Collaborator

    Thanks for sharing. I can understand why a dedicated PrimaryKeyError simplifies your workflow. EgeKaraismailogluQC and I also discussed that we're in favor of adding it as it improves readability, so I introduced it in #17.

  4. NilsSeibertQC commented on Mar 19, 2026

    @NilsSeibertQC
    Author

    Thanks!

  5. MariusMerkleQC commented on Mar 19, 2026

    @MariusMerkleQC
    Collaborator

    the specified columns not being present

    Note that we decided to raise a ValueError for this case, as it's an issue with the schema rather than the primary key.

  6. NilsSeibertQC commented on Mar 19, 2026

    @NilsSeibertQC
    Author

    Thanks for implementing, looks good. I understand the decision to raise ValueError on primary key columns not being present. Checking column existence beforehand is not much work.

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions