mirror of
https://github.com/explosion/spaCy.git
synced 2024-12-24 00:46:28 +03:00
Also raise error in Span.__reduce__
This commit is contained in:
parent
2d0c3c73f4
commit
fbf9f1edf1
|
@ -308,6 +308,12 @@ class Errors(object):
|
|||
"would always have to include its Doc and Vocab, which has "
|
||||
"practically no advantage over pickling the parent Doc directly. "
|
||||
"So instead of pickling the token, pickle the Doc it belongs to.")
|
||||
E112 = ("Pickling a span is not supported, because spans are only views "
|
||||
"of the parent Doc and can't exist on their own. A pickled span "
|
||||
"would always have to include its Doc and Vocab, which has "
|
||||
"practically no advantage over pickling the parent Doc directly. "
|
||||
"So instead of pickling the span, pickle the Doc it belongs to or "
|
||||
"use Span.as_doc to convert the span to a standalone Doc object.")
|
||||
|
||||
@add_codes
|
||||
class TempErrors(object):
|
||||
|
|
|
@ -7,7 +7,9 @@ from spacy.compat import pickle
|
|||
|
||||
|
||||
def test_issue2833(en_vocab):
|
||||
"""Test that a custom error is raised if a token is pickled."""
|
||||
"""Test that a custom error is raised if a token or span is pickled."""
|
||||
doc = Doc(en_vocab, words=["Hello", "world"])
|
||||
with pytest.raises(NotImplementedError):
|
||||
pickle.dumps(doc[0])
|
||||
with pytest.raises(NotImplementedError):
|
||||
pickle.dumps(doc[0:2])
|
||||
|
|
|
@ -141,6 +141,9 @@ cdef class Span:
|
|||
for i in range(self.start, self.end):
|
||||
yield self.doc[i]
|
||||
|
||||
def __reduce__(self):
|
||||
raise NotImplementedError(Errors.E112)
|
||||
|
||||
@property
|
||||
def _(self):
|
||||
"""User space for adding custom attribute extensions."""
|
||||
|
|
Loading…
Reference in New Issue
Block a user