Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

to_array(scalar) has bad error message #1410

Closed
jnothman opened this issue Oct 11, 2017 · 5 comments
Closed

to_array(scalar) has bad error message #1410

jnothman opened this issue Oct 11, 2017 · 5 comments
Labels
enhancement Feature requests and improvements help wanted (easy) Contributions welcome! (also suited for spaCy beginners) help wanted Contributions welcome! 🌙 nightly Discussion and contributions related to nightly builds

Comments

@jnothman
Copy link
Contributor

text.to_array(spacy.attrs.LEMMA)

raises

ValueError: Buffer has wrong number of dimensions (expected 1, got 0)

when it should either work or be clearer in the error: it expects a list, not a single attr.

Info about spaCy

  • spaCy version: 1.9.0
  • Python version: 3.5.2
  • Platform: Darwin-16.7.0-x86_64-i386-64bit
  • Installed models: en
@honnibal
Copy link
Member

honnibal commented Oct 11, 2017

Agreed, thanks.

I think we should make this work, i.e. LEMMA should be handled as [LEMMA]. We should handle "LEMMA" and "lemma" too.

@honnibal honnibal added enhancement Feature requests and improvements help wanted (easy) Contributions welcome! (also suited for spaCy beginners) labels Oct 11, 2017
@ines ines added the help wanted Contributions welcome! label Oct 13, 2017
@jnothman
Copy link
Contributor Author

If you want text.to_array(spacy.attrs.LEMMA) to work, I would return a 1d array rather than 2d for consistency with numpy semantics.

@honnibal
Copy link
Member

Does this describe the behaviour you expect? I added the option of an out=None array for further numpy consistency.

def to_array(self, attr_ids, out=None):
    """Export given token attributes to a numpy `ndarray`.

    If `attr_ids` is a sequence of M attributes, the output array will
    be of shape `(N, M)`, where N is the length of the `Doc`
    (in tokens). If `attr_ids` is a single attribute, the output shape will
    be (N,). You can specify attributes by integer ID (e.g. spacy.attrs.LEMMA)
    or string name (e.g. 'LEMMA' or 'lemma').

    By default, a new numpy array of dtype uint64 is created for the output.
    You can instead pass in an array using the `out` keyword argument.
    """

@jnothman
Copy link
Contributor Author

jnothman commented Oct 16, 2017 via email

@honnibal honnibal added the 🌙 nightly Discussion and contributions related to nightly builds label Oct 16, 2017
@ines ines closed this as completed Oct 20, 2017
@lock
Copy link

lock bot commented May 8, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators May 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Feature requests and improvements help wanted (easy) Contributions welcome! (also suited for spaCy beginners) help wanted Contributions welcome! 🌙 nightly Discussion and contributions related to nightly builds
Projects
None yet
Development

No branches or pull requests

3 participants