From 1a1cca6052a7afa679960e22a1b2038465e9cc28 Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Sun, 14 Jan 2018 14:48:51 +0100 Subject: [PATCH 1/4] Fix vectors.resize() on Py3. Closes #1539 --- spacy/tests/regression/test_issue1539.py | 10 ++++++++++ spacy/vectors.pyx | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 spacy/tests/regression/test_issue1539.py diff --git a/spacy/tests/regression/test_issue1539.py b/spacy/tests/regression/test_issue1539.py new file mode 100644 index 000000000..6665f8087 --- /dev/null +++ b/spacy/tests/regression/test_issue1539.py @@ -0,0 +1,10 @@ +'''Ensure vectors.resize() doesn't try to modify dictionary during iteration.''' +from __future__ import unicode_literals + +from ...vectors import Vectors + + +def test_issue1539(): + v = Vectors(shape=(10, 10), keys=[5,3,98,100]) + v.resize((100,100)) + diff --git a/spacy/vectors.pyx b/spacy/vectors.pyx index 46997cccf..96a9d3435 100644 --- a/spacy/vectors.pyx +++ b/spacy/vectors.pyx @@ -151,7 +151,7 @@ cdef class Vectors: filled = {row for row in self.key2row.values()} self._unset = {row for row in range(shape[0]) if row not in filled} removed_items = [] - for key, row in self.key2row.items(): + for key, row in list(self.key2row.items()): if row >= shape[0]: self.key2row.pop(key) removed_items.append((key, row)) From 5cbe913b6f2a42a3d109d6fa103d07b8f7c479cc Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Sun, 14 Jan 2018 14:55:58 +0100 Subject: [PATCH 2/4] Don't raise deprecation warning in property. Closes #1813, #1712 --- spacy/tokens/token.pyx | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/spacy/tokens/token.pyx b/spacy/tokens/token.pyx index c0ff8c845..2e1aa81b4 100644 --- a/spacy/tokens/token.pyx +++ b/spacy/tokens/token.pyx @@ -341,13 +341,14 @@ cdef class Token: property sent_start: def __get__(self): - util.deprecated( - "Token.sent_start is now deprecated. Use Token.is_sent_start " - "instead, which returns a boolean value or None if the answer " - "is unknown – instead of a misleading 0 for False and 1 for " - "True. It also fixes a quirk in the old logic that would " - "always set the property to 0 for the first word of the " - "document.") + # Raising a deprecation warning causes errors for autocomplete + #util.deprecated( + # "Token.sent_start is now deprecated. Use Token.is_sent_start " + # "instead, which returns a boolean value or None if the answer " + # "is unknown – instead of a misleading 0 for False and 1 for " + # "True. It also fixes a quirk in the old logic that would " + # "always set the property to 0 for the first word of the " + # "document.") # Handle broken backwards compatibility case: doc[0].sent_start # was False. if self.i == 0: From 0cb090e52671eb05a31f5944df7dd8dc1cc209df Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Sun, 14 Jan 2018 15:02:15 +0100 Subject: [PATCH 3/4] Fix infinite recursion in token.sent_start. Closes #1640 --- spacy/tokens/token.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spacy/tokens/token.pyx b/spacy/tokens/token.pyx index 2e1aa81b4..281c0a4be 100644 --- a/spacy/tokens/token.pyx +++ b/spacy/tokens/token.pyx @@ -354,7 +354,7 @@ cdef class Token: if self.i == 0: return False else: - return self.sent_start + return self.c.sent_start def __set__(self, value): self.is_sent_start = value From 465a6f64521d9568f1456ddf5337f9ea39d7aad3 Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Sun, 14 Jan 2018 15:06:30 +0100 Subject: [PATCH 4/4] Add missing Span.vocab property. Closes #1633 --- spacy/tokens/span.pyx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/spacy/tokens/span.pyx b/spacy/tokens/span.pyx index f09dfd134..10b8a7820 100644 --- a/spacy/tokens/span.pyx +++ b/spacy/tokens/span.pyx @@ -261,6 +261,11 @@ cdef class Span: self.start = start self.end = end + 1 + property vocab: + """RETURNS (Vocab): The Span's Doc's vocab.""" + def __get__(self): + return self.doc.vocab + property sent: """RETURNS (Span): The sentence span that the span is a part of.""" def __get__(self):