From b9c9cbb2cdcc4b379588207c03011b724f7a1600 Mon Sep 17 00:00:00 2001 From: svlandeg Date: Mon, 15 Jun 2020 11:53:31 +0200 Subject: [PATCH] informative error when calling to_array with wrong field --- spacy/tokens/doc.pyx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/spacy/tokens/doc.pyx b/spacy/tokens/doc.pyx index 511328068..8b519f1d6 100644 --- a/spacy/tokens/doc.pyx +++ b/spacy/tokens/doc.pyx @@ -699,8 +699,12 @@ cdef class Doc: # Handle inputs like doc.to_array(ORTH) py_attr_ids = [py_attr_ids] # Allow strings, e.g. 'lemma' or 'LEMMA' - py_attr_ids = [(IDS[id_.upper()] if hasattr(id_, "upper") else id_) - for id_ in py_attr_ids] + py_attr_ids = [id_.upper() if hasattr(id_, "upper") else id_ for id_ in py_attr_ids] + for key in py_attr_ids: + if key not in IDS: + keys = [k for k in IDS.keys() if not k.startswith("FLAG")] + raise ValueError(Errors.E983.format(dict_name="IDS", key=key, keys=keys)) + py_attr_ids = [IDS[id_] for id_ in py_attr_ids] # Make an array from the attributes --- otherwise our inner loop is # Python dict iteration. cdef np.ndarray attr_ids = numpy.asarray(py_attr_ids, dtype="i")