From aa69ecac04ea1a4dadf45990f989876940c472e9 Mon Sep 17 00:00:00 2001 From: verena <9377970+vpchung@users.noreply.github.com> Date: Wed, 8 May 2024 15:36:52 -0700 Subject: [PATCH] add exception handling; add new error message for ValueError exception --- score.py | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/score.py b/score.py index e5144ae..eb851d4 100644 --- a/score.py +++ b/score.py @@ -57,30 +57,31 @@ def main(): gold_file = extract_gs_file(args.goldstandard_folder) + scores = {"auc_roc": None, "auprc": None} + status = "INVALID" if res.get("validation_status") == "VALIDATED": - pred = pd.read_csv( - args.predictions_file, - usecols=PREDICTION_COLS, - dtype=PREDICTION_COLS - ) - gold = pd.read_csv( - gold_file, - usecols=GOLDSTANDARD_COLS, - dtype=GOLDSTANDARD_COLS - ) - scores = score(gold, "disease", pred, "disease_probability") - status = "SCORED" + try: + pred = pd.read_csv( + args.predictions_file, + usecols=PREDICTION_COLS, + dtype=PREDICTION_COLS + ) + gold = pd.read_csv( + gold_file, + usecols=GOLDSTANDARD_COLS, + dtype=GOLDSTANDARD_COLS + ) + scores = score(gold, "disease", pred, "disease_probability") + status = "SCORED" + errors = "" + except ValueError: + errors = "An error was encountered during scoring; submission not evaluated." else: - scores = {"auc_roc": None, "auprc": None} - status = "INVALID" + errors = "Submission could not be evaluated due to validation errors." res |= { "score_status": status, - "score_errors": ( - "" - if status == "SCORED" - else "Submission could not be evaluated due to validation errors." - ), + "score_errors": errors, **scores, } with open(args.output, "w", encoding="utf-8") as out: