Update Language.replace_pipe for disabled components (#8729)

* Fix the index where the replacement in inserted to account for
disabled components
* Allow `Language.replace_pipe` to replace disabled components
This commit is contained in:
Adriane Boyd 2021-07-19 10:06:12 +02:00 committed by GitHub
parent d717593eb7
commit e532c69475
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 2 deletions

View File

@ -872,14 +872,14 @@ class Language:
DOCS: https://spacy.io/api/language#replace_pipe
"""
if name not in self.pipe_names:
if name not in self.component_names:
raise ValueError(Errors.E001.format(name=name, opts=self.pipe_names))
if hasattr(factory_name, "__call__"):
err = Errors.E968.format(component=repr(factory_name), name=name)
raise ValueError(err)
# We need to delegate to Language.add_pipe here instead of just writing
# to Language.pipeline to make sure the configs are handled correctly
pipe_index = self.pipe_names.index(name)
pipe_index = self.component_names.index(name)
self.remove_pipe(name)
if not len(self._components) or pipe_index == len(self._components):
# we have no components to insert before/after, or we're replacing the last component