From 76e3e695afe191f96416181c8905917652c0cde3 Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Sat, 29 Dec 2018 16:24:40 +0100 Subject: [PATCH] Allow single string attributes in doc.to_array() Previously inputs like doc.to_array('ORTH') didn't work. Closes #3064 --- spacy/tokens/doc.pyx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/spacy/tokens/doc.pyx b/spacy/tokens/doc.pyx index 42ecb5644..4d12548be 100644 --- a/spacy/tokens/doc.pyx +++ b/spacy/tokens/doc.pyx @@ -594,10 +594,13 @@ cdef class Doc: cdef attr_id_t feature cdef np.ndarray[attr_t, ndim=2] output # Handle scalar/list inputs of strings/ints for py_attr_ids - if not hasattr(py_attr_ids, '__iter__') \ - and not isinstance(py_attr_ids, basestring_): + # See also #3064 + if isinstance(py_attr_ids, basestring_): + # Handle inputs like doc.to_array('ORTH') + py_attr_ids = [py_attr_ids] + elif not hasattr(py_attr_ids, '__iter__'): + # 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]