From e532c6947569a8d707e630bd98174c84f3185b6e Mon Sep 17 00:00:00 2001 From: Adriane Boyd Date: Mon, 19 Jul 2021 10:06:12 +0200 Subject: [PATCH] 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 --- spacy/language.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spacy/language.py b/spacy/language.py index 7ceb266bf..589dca2bf 100644 --- a/spacy/language.py +++ b/spacy/language.py @@ -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