Fix exceptions for Morphology.__reduce__ (#5792)

Pickle exceptions in the MORPH_RULES format instead of the internal
format after the recent `Morphology.__init__` changes.
This commit is contained in:
Adriane Boyd 2020-07-22 15:00:25 +02:00 committed by GitHub
parent 43b960c01b
commit b84fd70cc3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 1 deletions

View File

@ -96,7 +96,7 @@ cdef class Morphology:
def __reduce__(self):
return (Morphology, (self.strings, self.tag_map, self.lemmatizer,
self._exc), None, None)
self.exc), None, None)
def add(self, features):
"""Insert a morphological analysis in the morphology table, if not

View File

@ -0,0 +1,22 @@
import pytest
import pickle
from spacy.morphology import Morphology
from spacy.strings import StringStore
from spacy.lemmatizer import Lemmatizer
from spacy.lookups import Lookups
@pytest.fixture
def morphology():
tag_map = {"A": {"POS": "X"}, "B": {"POS": "NOUN"}}
exc = {"A": {"a": {"POS": "VERB"}}}
lemmatizer = Lemmatizer(Lookups())
return Morphology(StringStore(), tag_map, lemmatizer, exc=exc)
def test_morphology_pickle_roundtrip(morphology):
b = pickle.dumps(morphology)
reloaded_morphology = pickle.loads(b)
assert morphology.tag_map == reloaded_morphology.tag_map
assert morphology.exc == reloaded_morphology.exc