mirror of
https://github.com/explosion/spaCy.git
synced 2025-01-27 09:44:36 +03:00
Raise if disabled components are removed before DisabledPipes.restore
This commit is contained in:
parent
1e0363290e
commit
10da74382f
|
@ -136,11 +136,10 @@ class Errors:
|
||||||
"after (component name or index), first (True) or last (True). "
|
"after (component name or index), first (True) or last (True). "
|
||||||
"Invalid configuration: {args}. Existing components: {opts}")
|
"Invalid configuration: {args}. Existing components: {opts}")
|
||||||
E007 = ("'{name}' already exists in pipeline. Existing names: {opts}")
|
E007 = ("'{name}' already exists in pipeline. Existing names: {opts}")
|
||||||
E008 = ("Some current components would be lost when restoring previous "
|
E008 = ("Can't restore disabled pipeline component '{name}' because it "
|
||||||
"pipeline state. If you added components after calling "
|
"doesn't exist in the pipeline anymore. If you want to remove "
|
||||||
"`nlp.select_pipes()`, you should remove them explicitly with "
|
"components from the pipeline, you should do it before calling "
|
||||||
"`nlp.remove_pipe()` before the pipeline is restored. Names of "
|
"`nlp.select_pipes()` or after restoring the disabled components.")
|
||||||
"the new components: {names}")
|
|
||||||
E010 = ("Word vectors set to length 0. This may be because you don't have "
|
E010 = ("Word vectors set to length 0. This may be because you don't have "
|
||||||
"a model installed or loaded, or because your model doesn't "
|
"a model installed or loaded, or because your model doesn't "
|
||||||
"include word vectors. For more info, see the docs:\n"
|
"include word vectors. For more info, see the docs:\n"
|
||||||
|
|
|
@ -1720,9 +1720,9 @@ class DisabledPipes(list):
|
||||||
def restore(self) -> None:
|
def restore(self) -> None:
|
||||||
"""Restore the pipeline to its state when DisabledPipes was created."""
|
"""Restore the pipeline to its state when DisabledPipes was created."""
|
||||||
for name in self.names:
|
for name in self.names:
|
||||||
|
if name not in self.nlp._pipe_names:
|
||||||
|
raise ValueError(Errors.E008.format(name=name))
|
||||||
self.nlp.enable_pipe(name)
|
self.nlp.enable_pipe(name)
|
||||||
# TODO: maybe add some more checks / catch errors that may occur if
|
|
||||||
# user removes a disabled pipe in the with block
|
|
||||||
self[:] = []
|
self[:] = []
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -181,6 +181,11 @@ def test_select_pipes_errors(nlp):
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
nlp.select_pipes(enable=[], disable=["c3"])
|
nlp.select_pipes(enable=[], disable=["c3"])
|
||||||
|
|
||||||
|
disabled = nlp.select_pipes(disable=["c2"])
|
||||||
|
nlp.remove_pipe("c2")
|
||||||
|
with pytest.raises(ValueError):
|
||||||
|
disabled.restore()
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("n_pipes", [100])
|
@pytest.mark.parametrize("n_pipes", [100])
|
||||||
def test_add_lots_of_pipes(nlp, n_pipes):
|
def test_add_lots_of_pipes(nlp, n_pipes):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user