From a5ea0fdf5a9656525dd8d78b7d6979538727a776 Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Wed, 8 Nov 2017 22:18:37 +0100 Subject: [PATCH] Fix #1518: vocab.vectors.resize() didn't work --- spacy/tests/regression/test_issue1518.py | 7 +++++++ spacy/vectors.pyx | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 spacy/tests/regression/test_issue1518.py diff --git a/spacy/tests/regression/test_issue1518.py b/spacy/tests/regression/test_issue1518.py new file mode 100644 index 000000000..d5c6eb914 --- /dev/null +++ b/spacy/tests/regression/test_issue1518.py @@ -0,0 +1,7 @@ +from ...vectors import Vectors + +def test_issue1518(): + '''Test vectors.resize() works.''' + vectors = Vectors(shape=(10, 10)) + vectors.add(u'hello', row=2) + vectors.resize((5, 9)) diff --git a/spacy/vectors.pyx b/spacy/vectors.pyx index 8b85bba9c..6c5018d13 100644 --- a/spacy/vectors.pyx +++ b/spacy/vectors.pyx @@ -150,7 +150,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 dict(self.key2row.items()): + for key, row in self.key2row.items(): if row >= shape[0]: self.key2row.pop(key) removed_items.append((key, row))