From 2fc33e8024487974c6fbc6941026b75f8e89a07b Mon Sep 17 00:00:00 2001 From: "Yubing (Tom) Dong" Date: Tue, 6 Oct 2015 00:56:33 -0700 Subject: [PATCH] Allow step=1 when slicing a Doc --- spacy/tokens/doc.pyx | 2 +- tests/tokens/test_tokens_api.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/spacy/tokens/doc.pyx b/spacy/tokens/doc.pyx index 8a7d12555..ce278d868 100644 --- a/spacy/tokens/doc.pyx +++ b/spacy/tokens/doc.pyx @@ -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: diff --git a/tests/tokens/test_tokens_api.py b/tests/tokens/test_tokens_api.py index a7311932f..fc1b52143 100644 --- a/tests/tokens/test_tokens_api.py +++ b/tests/tokens/test_tokens_api.py @@ -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):