mirror of
https://github.com/explosion/spaCy.git
synced 2025-02-11 17:10:36 +03:00
fix error catching
This commit is contained in:
parent
b9c9cbb2cd
commit
b4d914ec77
|
@ -699,12 +699,12 @@ cdef class Doc:
|
||||||
# Handle inputs like doc.to_array(ORTH)
|
# Handle inputs like doc.to_array(ORTH)
|
||||||
py_attr_ids = [py_attr_ids]
|
py_attr_ids = [py_attr_ids]
|
||||||
# Allow strings, e.g. 'lemma' or 'LEMMA'
|
# Allow strings, e.g. 'lemma' or 'LEMMA'
|
||||||
py_attr_ids = [id_.upper() if hasattr(id_, "upper") else id_ for id_ in py_attr_ids]
|
try:
|
||||||
for key in py_attr_ids:
|
py_attr_ids = [(IDS[id_.upper()] if hasattr(id_, "upper") else id_)
|
||||||
if key not in IDS:
|
for id_ in py_attr_ids]
|
||||||
|
except KeyError as msg:
|
||||||
keys = [k for k in IDS.keys() if not k.startswith("FLAG")]
|
keys = [k for k in IDS.keys() if not k.startswith("FLAG")]
|
||||||
raise ValueError(Errors.E983.format(dict_name="IDS", key=key, keys=keys))
|
raise KeyError(Errors.E983.format(dict_name="IDS", key=msg, keys=keys))
|
||||||
py_attr_ids = [IDS[id_] for id_ in py_attr_ids]
|
|
||||||
# Make an array from the attributes --- otherwise our inner loop is
|
# Make an array from the attributes --- otherwise our inner loop is
|
||||||
# Python dict iteration.
|
# Python dict iteration.
|
||||||
cdef np.ndarray attr_ids = numpy.asarray(py_attr_ids, dtype="i")
|
cdef np.ndarray attr_ids = numpy.asarray(py_attr_ids, dtype="i")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user