From de838a08666a1868cd8d219f1f23e4ae6d86d01c Mon Sep 17 00:00:00 2001 From: thomashacker Date: Wed, 16 Nov 2022 14:04:55 +0100 Subject: [PATCH] remove warnings from get_lang_class --- spacy/cli/convert.py | 10 ++++++++++ spacy/errors.py | 2 +- spacy/tests/test_language.py | 9 ++------- spacy/util.py | 2 -- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/spacy/cli/convert.py b/spacy/cli/convert.py index 04eb7078f..2e150d3ae 100644 --- a/spacy/cli/convert.py +++ b/spacy/cli/convert.py @@ -13,6 +13,8 @@ from ..tokens import Doc, DocBin from ..training.converters import iob_to_docs, conll_ner_to_docs, json_to_docs from ..training.converters import conllu_to_docs +import warnings +from ..errors import Warnings # Converters are matched by file extension except for ner/iob, which are # matched by file extension and content. To add a converter, add a new @@ -110,6 +112,14 @@ def convert( input_path = Path(input_path) if not msg: msg = Printer(no_print=silent) + + # Add warnings for renamed language code in v4 + renamed_lang_codes = {"xx": "mul", "is": "isl"} + if lang in renamed_lang_codes: + warnings.warn( + Warnings.W124.format(lang=lang, renamed_lang=renamed_lang_codes[lang]) + ) + ner_map = srsly.read_json(ner_map) if ner_map is not None else None doc_files = [] for input_loc in walk_directory(input_path, converter): diff --git a/spacy/errors.py b/spacy/errors.py index 7f3c58af7..596a989b3 100644 --- a/spacy/errors.py +++ b/spacy/errors.py @@ -215,7 +215,7 @@ class Warnings(metaclass=ErrorsWithCodes): W123 = ("Argument {arg} with value {arg_value} is used instead of {config_value} as specified in the config. Be " "aware that this might affect other components in your pipeline.") # New warnings added in v4.x - W124 = ("Language code '{lang}' was not found and replaced with '{renamed_lang}'. Language codes like 'xx' and 'is' were renamed to 'mul' and 'isl' in v4.") + W124 = ("Language code '{lang}' was replaced with '{renamed_lang}' in v4.") class Errors(metaclass=ErrorsWithCodes): diff --git a/spacy/tests/test_language.py b/spacy/tests/test_language.py index c8fbdbad8..e4cf8ea18 100644 --- a/spacy/tests/test_language.py +++ b/spacy/tests/test_language.py @@ -590,13 +590,8 @@ def test_blank_languages(lang, target): Test that we can get spacy.blank in various languages, including codes that are defined to be equivalent or that match by CLDR language matching. """ - if lang == "en": - nlp = spacy.blank(lang) - assert nlp.lang == target - else: - with pytest.warns(UserWarning): - nlp = spacy.blank(lang) - assert nlp.lang == target + nlp = spacy.blank(lang) + assert nlp.lang == target @pytest.mark.parametrize("value", [False, None, ["x", "y"], Language, Vocab]) diff --git a/spacy/util.py b/spacy/util.py index 851527cb0..e1c49b51e 100644 --- a/spacy/util.py +++ b/spacy/util.py @@ -327,8 +327,6 @@ def get_lang_class(lang: str) -> Type["Language"]: match = None if match: - if match != lang: - warnings.warn(Warnings.W124.format(lang=lang, renamed_lang=match)) lang = match module = importlib.import_module(f".lang.{lang}", "spacy") else: