From 8d7af5b2b155c36ced0082a227839887605da0e6 Mon Sep 17 00:00:00 2001 From: Sofie Van Landeghem Date: Mon, 12 Apr 2021 14:35:57 +0200 Subject: [PATCH] Ensure hyphen in config file works as string value (#7642) * add test for serializing '-' in a config file * bump srsly to 2.4.1 --- requirements.txt | 2 +- setup.cfg | 2 +- .../tests/serialize/test_serialize_config.py | 31 ++++++++++++++++++- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/requirements.txt b/requirements.txt index f86efff3f..5be39f59f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,7 +7,7 @@ blis>=0.4.0,<0.8.0 ml_datasets>=0.2.0,<0.3.0 murmurhash>=0.28.0,<1.1.0 wasabi>=0.8.1,<1.1.0 -srsly>=2.4.0,<3.0.0 +srsly>=2.4.1,<3.0.0 catalogue>=2.0.1,<2.1.0 typer>=0.3.0,<0.4.0 pathy>=0.3.5 diff --git a/setup.cfg b/setup.cfg index 92e758aec..f8672034f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -44,7 +44,7 @@ install_requires = thinc>=8.0.2,<8.1.0 blis>=0.4.0,<0.8.0 wasabi>=0.8.1,<1.1.0 - srsly>=2.4.0,<3.0.0 + srsly>=2.4.1,<3.0.0 catalogue>=2.0.1,<2.1.0 typer>=0.3.0,<0.4.0 pathy>=0.3.5 diff --git a/spacy/tests/serialize/test_serialize_config.py b/spacy/tests/serialize/test_serialize_config.py index 66b66b744..2cd0e4ab6 100644 --- a/spacy/tests/serialize/test_serialize_config.py +++ b/spacy/tests/serialize/test_serialize_config.py @@ -4,7 +4,7 @@ import spacy from spacy.lang.en import English from spacy.lang.de import German from spacy.language import Language, DEFAULT_CONFIG, DEFAULT_CONFIG_PRETRAIN_PATH -from spacy.util import registry, load_model_from_config, load_config +from spacy.util import registry, load_model_from_config, load_config, load_config_from_str from spacy.ml.models import build_Tok2Vec_model, build_tb_parser_model from spacy.ml.models import MultiHashEmbed, MaxoutWindowEncoder from spacy.schemas import ConfigSchema, ConfigSchemaPretrain @@ -465,3 +465,32 @@ def test_config_only_resolve_relevant_blocks(): nlp.initialize() nlp.config["initialize"]["lookups"] = None nlp.initialize() + + +def test_hyphen_in_config(): + hyphen_config_str = """ + [nlp] + lang = "en" + pipeline = ["my_punctual_component"] + + [components] + + [components.my_punctual_component] + factory = "my_punctual_component" + punctuation = ["?","-"] + """ + + @spacy.Language.factory("my_punctual_component") + class MyPunctualComponent(object): + name = "my_punctual_component" + + def __init__( + self, + nlp, + name, + punctuation, + ): + self.punctuation = punctuation + + nlp = English.from_config(load_config_from_str(hyphen_config_str)) + assert nlp.get_pipe("my_punctual_component").punctuation == ['?', '-']