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):
"""
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."
"Try: list(doc)[start:stop:step] instead.")
if i.start is None:

View File

@ -16,6 +16,8 @@ def test_getitem(EN):
assert not '/'.join(token.orth_ for token in span)
span = tokens[1:4]
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):
tokens[1:4:2]
with pytest.raises(ValueError):