From 708a4d27ebd47fde3dd15f0530fdebc4cf40dd01 Mon Sep 17 00:00:00 2001 From: Yohei Tamura Date: Mon, 20 Jan 2020 20:17:46 +0900 Subject: [PATCH] fix nlp.evaluate (#4924) (#4925) * new file: test_issue4924.py * modified: spacy/gold.pyx * modified: test_issue4924.py for python2 --- spacy/gold.pyx | 5 +++++ spacy/tests/regression/test_issue4924.py | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 spacy/tests/regression/test_issue4924.py diff --git a/spacy/gold.pyx b/spacy/gold.pyx index 1d7f80c92..3884e1cba 100644 --- a/spacy/gold.pyx +++ b/spacy/gold.pyx @@ -694,6 +694,11 @@ cdef class GoldParse: self.cats = {} if cats is None else dict(cats) self.links = links + # orig_annot is used as an iterator in `nlp.evalate` even if self.length == 0, + # so set a empty list to avoid error. + # if self.lenght > 0, this is modified latter. + self.orig_annot = [] + # avoid allocating memory if the doc does not contain any tokens if self.length > 0: if words is None: diff --git a/spacy/tests/regression/test_issue4924.py b/spacy/tests/regression/test_issue4924.py new file mode 100644 index 000000000..8aea2c3d5 --- /dev/null +++ b/spacy/tests/regression/test_issue4924.py @@ -0,0 +1,16 @@ +# coding: utf8 +from __future__ import unicode_literals + +import pytest + +import spacy + + +@pytest.fixture +def nlp(): + return spacy.blank("en") + + +def test_evaluate(nlp): + docs_golds = [("", {})] + nlp.evaluate(docs_golds)