mirror of
https://github.com/explosion/spaCy.git
synced 2025-01-26 09:14:32 +03:00
Fix pipeline analysis on remove pipe (#4557)
Validate *after* component is removed, not before
This commit is contained in:
parent
6b874ef096
commit
afe4a428f7
|
@ -402,9 +402,10 @@ class Language(object):
|
|||
"""
|
||||
if name not in self.pipe_names:
|
||||
raise ValueError(Errors.E001.format(name=name, opts=self.pipe_names))
|
||||
removed = self.pipeline.pop(self.pipe_names.index(name))
|
||||
if ENABLE_PIPELINE_ANALYSIS:
|
||||
analyze_all_pipes(self.pipeline)
|
||||
return self.pipeline.pop(self.pipe_names.index(name))
|
||||
return removed
|
||||
|
||||
def __call__(self, text, disable=[], component_cfg=None):
|
||||
"""Apply the pipeline to some text. The text can span multiple sentences,
|
||||
|
|
|
@ -145,3 +145,24 @@ def test_analysis_validate_attrs_valid():
|
|||
def test_analysis_validate_attrs_invalid(attr):
|
||||
with pytest.raises(ValueError):
|
||||
validate_attrs([attr])
|
||||
|
||||
|
||||
def test_analysis_validate_attrs_remove_pipe():
|
||||
"""Test that attributes are validated correctly on remove."""
|
||||
spacy.language.ENABLE_PIPELINE_ANALYSIS = True
|
||||
|
||||
@component("c1", assigns=["token.tag"])
|
||||
def c1(doc):
|
||||
return doc
|
||||
|
||||
@component("c2", requires=["token.pos"])
|
||||
def c2(doc):
|
||||
return doc
|
||||
|
||||
nlp = Language()
|
||||
nlp.add_pipe(c1)
|
||||
with pytest.warns(UserWarning):
|
||||
nlp.add_pipe(c2)
|
||||
with pytest.warns(None) as record:
|
||||
nlp.remove_pipe("c2")
|
||||
assert not record.list
|
||||
|
|
Loading…
Reference in New Issue
Block a user