Fix vectors.resize() on Py3. Closes #1539

This commit is contained in:
Matthew Honnibal 2018-01-14 14:48:51 +01:00
parent 438050643c
commit 1a1cca6052
2 changed files with 11 additions and 1 deletions

View File

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

View File

@ -151,7 +151,7 @@ cdef class Vectors:
filled = {row for row in self.key2row.values()} filled = {row for row in self.key2row.values()}
self._unset = {row for row in range(shape[0]) if row not in filled} self._unset = {row for row in range(shape[0]) if row not in filled}
removed_items = [] removed_items = []
for key, row in self.key2row.items(): for key, row in list(self.key2row.items()):
if row >= shape[0]: if row >= shape[0]:
self.key2row.pop(key) self.key2row.pop(key)
removed_items.append((key, row)) removed_items.append((key, row))