fix(module): export EvaluationModuleError and wrap _compute failures#759
Open
xodn348 wants to merge 1 commit into
Open
fix(module): export EvaluationModuleError and wrap _compute failures#759xodn348 wants to merge 1 commit into
xodn348 wants to merge 1 commit into
Conversation
…e exceptions Adds EvaluationModuleError exception class to evaluate/module.py and exports it from evaluate/__init__.py so callers can catch evaluate-specific failures without catching broad Exception or importing internal sklearn/numpy types. Wraps the _compute() call in EvaluationModule.compute() so that raw ValueError/KeyError/etc. from metric backends surface as EvaluationModuleError instead of leaking implementation details. Closes 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.
Summary
EvaluationModuleErrorwas absent fromevaluate's public API, so callers hadno way to catch evaluate-specific failures without catching the broad
Exceptionbase class or importing internal sklearn/numpy error types. This made it
impossible to write
except evaluate.EvaluationModuleError— doing so raised anAttributeErrorbecause the symbol was never exported.This PR adds the
EvaluationModuleErrorclass tosrc/evaluate/module.pyandexports it from
src/evaluate/__init__.py. It also wraps the_compute()callinside
EvaluationModule.compute()so that raw backend exceptions (e.g.ValueError: y_true contains only one labelfrom sklearn) surface asEvaluationModuleErrorwith a descriptive message, rather than leakingimplementation details to callers.
Issue
Fixes #758
Local verification
Risk
Wrapping
_compute()is a breaking change only for callers that currently catchthe raw
ValueError/KeyError/etc. raised by metric backends and rely on theirexact type — but that pattern was already undocumented and fragile. The
EvaluationModuleErrorpreserves the original exception viafrom eso__cause__is always available. No existing test expectations were changed.