diff --git a/spacy/cli/evaluate.py b/spacy/cli/evaluate.py index 539a182f4..02f9b6528 100644 --- a/spacy/cli/evaluate.py +++ b/spacy/cli/evaluate.py @@ -175,10 +175,13 @@ def render_parses( def print_prf_per_type( msg: Printer, scores: Dict[str, Dict[str, float]], name: str, type: str ) -> None: - data = [ - (k, f"{v['p']*100:.2f}", f"{v['r']*100:.2f}", f"{v['f']*100:.2f}") - for k, v in scores.items() - ] + data = [] + for key, value in scores.items(): + row = [key] + for k in ("p", "r", "f"): + v = value[k] + row.append(f"{v * 100:.2f}" if isinstance(v, (int, float)) else v) + data.append(row) msg.table( data, header=("", "P", "R", "F"), @@ -191,7 +194,10 @@ def print_textcats_auc_per_cat( msg: Printer, scores: Dict[str, Dict[str, float]] ) -> None: msg.table( - [(k, f"{v:.2f}") for k, v in scores.items()], + [ + (k, f"{v:.2f}" if isinstance(v, (float, int)) else v) + for k, v in scores.items() + ], header=("", "ROC AUC"), aligns=("l", "r"), title="Textcat ROC AUC (per label)", diff --git a/spacy/tests/regression/test_issue7019.py b/spacy/tests/regression/test_issue7019.py new file mode 100644 index 000000000..53958b594 --- /dev/null +++ b/spacy/tests/regression/test_issue7019.py @@ -0,0 +1,12 @@ +from spacy.cli.evaluate import print_textcats_auc_per_cat, print_prf_per_type +from wasabi import msg + + +def test_issue7019(): + scores = {"LABEL_A": 0.39829102, "LABEL_B": 0.938298329382, "LABEL_C": None} + print_textcats_auc_per_cat(msg, scores) + scores = { + "LABEL_A": {"p": 0.3420302, "r": 0.3929020, "f": 0.49823928932}, + "LABEL_B": {"p": None, "r": None, "f": None}, + } + print_prf_per_type(msg, scores, name="foo", type="bar")