Allow step=1 when slicing a Doc

This commit is contained in:
Yubing (Tom) Dong 2015-10-06 00:56:33 -07:00
parent 73566899bf
commit 2fc33e8024
2 changed files with 3 additions and 1 deletions

View File

@ -87,7 +87,7 @@ cdef class Doc:
token (Token): token (Token):
""" """
if isinstance(i, slice): if isinstance(i, slice):
if i.step is not None: if not (i.step is None or i.step == 1):
raise ValueError("Stepped slices not supported in Span objects." raise ValueError("Stepped slices not supported in Span objects."
"Try: list(doc)[start:stop:step] instead.") "Try: list(doc)[start:stop:step] instead.")
if i.start is None: if i.start is None:

View File

@ -16,6 +16,8 @@ def test_getitem(EN):
assert not '/'.join(token.orth_ for token in span) assert not '/'.join(token.orth_ for token in span)
span = tokens[1:4] span = tokens[1:4]
assert '/'.join(token.orth_ for token in span) == 'it/back/!' assert '/'.join(token.orth_ for token in span) == 'it/back/!'
span = tokens[1:4:1]
assert '/'.join(token.orth_ for token in span) == 'it/back/!'
with pytest.raises(ValueError): with pytest.raises(ValueError):
tokens[1:4:2] tokens[1:4:2]
with pytest.raises(ValueError): with pytest.raises(ValueError):