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))