mirror of https://github.com/explosion/spaCy.git
Allow step=1 when slicing a Doc
This commit is contained in:
parent
73566899bf
commit
2fc33e8024
|
@ -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:
|
||||||
|
|
|
@ -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):
|
||||||
|
|
Loading…
Reference in New Issue