mirror of
https://github.com/explosion/spaCy.git
synced 2024-12-25 17:36:30 +03:00
Bugfix in nlp.replace_pipe (#5875)
* bugfix and unit test * merge two conditions
This commit is contained in:
parent
b795f02fbd
commit
b88c5c701a
|
@ -805,7 +805,8 @@ class Language:
|
|||
# to Language.pipeline to make sure the configs are handled correctly
|
||||
pipe_index = self.pipe_names.index(name)
|
||||
self.remove_pipe(name)
|
||||
if not len(self.pipeline): # we have no components to insert before/after
|
||||
if not len(self.pipeline) or pipe_index == len(self.pipeline):
|
||||
# we have no components to insert before/after, or we're replacing the last component
|
||||
self.add_pipe(factory_name, name=name)
|
||||
else:
|
||||
self.add_pipe(factory_name, name=name, before=pipe_index)
|
||||
|
|
|
@ -70,6 +70,14 @@ def test_replace_pipe(nlp, name, replacement, invalid_replacement):
|
|||
assert nlp.get_pipe(name) == nlp.create_pipe(replacement)
|
||||
|
||||
|
||||
def test_replace_last_pipe(nlp):
|
||||
nlp.add_pipe("sentencizer")
|
||||
nlp.add_pipe("ner")
|
||||
assert nlp.pipe_names == ["sentencizer", "ner"]
|
||||
nlp.replace_pipe("ner", "ner")
|
||||
assert nlp.pipe_names == ["sentencizer", "ner"]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("old_name,new_name", [("old_pipe", "new_pipe")])
|
||||
def test_rename_pipe(nlp, old_name, new_name):
|
||||
with pytest.raises(ValueError):
|
||||
|
|
Loading…
Reference in New Issue
Block a user