Export EvaluationModuleError and wrap _compute failures (fixes #758)#768
Open
Robby955 wants to merge 1 commit into
Open
Export EvaluationModuleError and wrap _compute failures (fixes #758)#768Robby955 wants to merge 1 commit into
Robby955 wants to merge 1 commit into
Conversation
Raw exceptions from a metric's _compute (for example sklearn ValueError or KeyError) previously propagated to callers of compute() unchanged, and there was no public error type to catch. Add EvaluationModuleError, export it from the package, and wrap failures from _compute in it while preserving the original exception as __cause__. Fixes huggingface#758
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Raw exceptions from a metric's _compute (for example sklearn ValueError or KeyError) currently propagate to callers of compute() unchanged, and there is no public evaluate error type to catch, so users fall back on a broad except Exception.
This adds an EvaluationModuleError class, exports it from the package, and wraps failures coming out of _compute in it. The original exception is kept on cause so tracebacks and debugging are unaffected.
Note: the linked issue assumed EvaluationModuleError already existed internally; it did not, so this PR also defines the class.
Added tests in tests/test_metric.py covering that the error is importable from the public API and that a failing _compute raises EvaluationModuleError rather than a bare ValueError.
Fixes #758