Skip to content

Compare operator (==) behaves unexpectedly on spacy tokens #1257

@ank-26

Description

@ank-26
nlp = spacy.load("en")
doc1 = nlp(u"I am here")
doc2 = nlp(u"Hello")

doc1[0] == doc2[0]
True

In the above snippet, spacy is treating 1st token of both the docs as equal. So, in the below source code the richcmp method it is using index to compare.

def __richcmp__(self, Token other, int op):
        # http://cython.readthedocs.io/en/latest/src/userguide/special_methods.html
        my = self.idx
        their = other.idx if other is not None else None

Environment

  • Python version: 2.7.10
  • Platform: Darwin-16.0.0-x86_64-i386-64bit
  • spaCy version: 1.9.0
  • Installed models: en

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugBugs and behaviour differing from documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions