Skip to content

Commit

Permalink
Fix (and test) vector pickling
Browse files Browse the repository at this point in the history
  • Loading branch information
honnibal committed Dec 7, 2017
1 parent 2ae4755 commit 36b47e3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
4 changes: 4 additions & 0 deletions spacy/tests/test_pickles.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import pytest
import dill as pickle
import numpy

from ..vocab import Vocab
from ..attrs import NORM
Expand All @@ -22,6 +23,7 @@ def test_pickle_string_store(stringstore, text1, text2):
@pytest.mark.parametrize('text1,text2', [('dog', 'cat')])
def test_pickle_vocab(text1, text2):
vocab = Vocab(lex_attr_getters={int(NORM): lambda string: string[:-1]})
vocab.set_vector('dog', numpy.ones((5,), dtype='f'))
lex1 = vocab[text1]
lex2 = vocab[text2]
assert lex1.norm_ == text1[:-1]
Expand All @@ -33,3 +35,5 @@ def test_pickle_vocab(text1, text2):
assert unpickled[text1].norm == lex1.norm
assert unpickled[text2].norm == lex2.norm
assert unpickled[text1].norm != unpickled[text2].norm
assert unpickled.vectors is not None
assert list(vocab['dog'].vector) == [1.,1.,1.,1.,1.]
1 change: 1 addition & 0 deletions spacy/vectors.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def unpickle_vectors(keys_and_rows, data):
vectors = Vectors(data=data)
for key, row in keys_and_rows:
vectors.add(key, row=row)
return vectors


cdef class Vectors:
Expand Down

0 comments on commit 36b47e3

Please sign in to comment.