diff --git a/spacy/tests/regression/test_issue1375.py b/spacy/tests/regression/test_issue1375.py index 72070758d..6f74d9a6d 100644 --- a/spacy/tests/regression/test_issue1375.py +++ b/spacy/tests/regression/test_issue1375.py @@ -3,7 +3,7 @@ import pytest from ...vocab import Vocab from ...tokens.doc import Doc -@pytest.mark.xfail + def test_issue1375(): '''Test that token.nbor() raises IndexError for out-of-bounds access.''' doc = Doc(Vocab(), words=['0', '1', '2']) diff --git a/spacy/tokens/token.pyx b/spacy/tokens/token.pyx index 9ff59eabe..514934ca7 100644 --- a/spacy/tokens/token.pyx +++ b/spacy/tokens/token.pyx @@ -127,6 +127,9 @@ cdef class Token: i (int): The relative position of the token to get. Defaults to 1. RETURNS (Token): The token at position `self.doc[self.i+i]`. """ + if self.i+i < 0 or (self.i+i >= len(self.doc)): + msg = "Error accessing doc[%d].nbor(%d), for doc of length %d" + raise IndexError(msg % (self.i, i, len(self.doc))) return self.doc[self.i+i] def similarity(self, other):