Fix Pipe.to_bytes() when model uninitialized

Closes #3289
This commit is contained in:
Matthew Honnibal 2019-02-21 09:42:02 +01:00
parent 6574e4f2d3
commit a137e8b418
2 changed files with 2 additions and 7 deletions

View File

@ -145,9 +145,7 @@ class Pipe(object):
"""Serialize the pipe to a bytestring.""" """Serialize the pipe to a bytestring."""
serialize = OrderedDict() serialize = OrderedDict()
serialize["cfg"] = lambda: srsly.json_dumps(self.cfg) serialize["cfg"] = lambda: srsly.json_dumps(self.cfg)
if self.model in (True, False, None): if self.model not in (True, False, None):
serialize["model"] = lambda: self.model
else:
serialize["model"] = self.model.to_bytes serialize["model"] = self.model.to_bytes
serialize["vocab"] = self.vocab.to_bytes serialize["vocab"] = self.vocab.to_bytes
return util.to_bytes(serialize, exclude) return util.to_bytes(serialize, exclude)
@ -538,9 +536,7 @@ class Tagger(Pipe):
def to_bytes(self, **exclude): def to_bytes(self, **exclude):
serialize = OrderedDict() serialize = OrderedDict()
if self.model in (None, True, False): if self.model not in (None, True, False):
serialize['model'] = lambda: self.model
else:
serialize['model'] = self.model.to_bytes serialize['model'] = self.model.to_bytes
serialize['vocab'] = self.vocab.to_bytes serialize['vocab'] = self.vocab.to_bytes
serialize['cfg'] = lambda: srsly.json_dumps(self.cfg) serialize['cfg'] = lambda: srsly.json_dumps(self.cfg)

View File

@ -5,7 +5,6 @@ import pytest
from spacy.lang.en import English from spacy.lang.en import English
@pytest.mark.xfail
def test_issue3289(): def test_issue3289():
"""Test that Language.to_bytes handles serializing a pipeline component """Test that Language.to_bytes handles serializing a pipeline component
with an uninitialized model.""" with an uninitialized model."""