From 0a64338da0e9c909781dfe5497f7e7c69ef71ba3 Mon Sep 17 00:00:00 2001 From: Mariia Borodii Date: Mon, 22 Jun 2026 12:02:07 +0000 Subject: [PATCH 1/2] Document extract.codes strategy, min/max_length, sort_order, disallowed_patterns, include_multi_part_tokens, and extract_raw params --- wrangles/extract.py | 15 +++++++++++++++ wrangles/recipe_wrangles/extract.py | 4 ++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/wrangles/extract.py b/wrangles/extract.py index bfe559c4..3d526c3a 100644 --- a/wrangles/extract.py +++ b/wrangles/extract.py @@ -427,6 +427,21 @@ def codes( e.g. 'Something ABC123ZZ something' -> 'ABC123ZZ' + :param input: A string or list of strings to search for codes. + :param first_element: Get the first element from results. + :param min_length: Minimum length of allowed results. + :param max_length: Maximum length of allowed results. + :param strategy: How aggressive to be at removing false positives such as + measurements. One of 'lenient', 'balanced' or 'strict'. Default is + 'balanced'. Note that 'balanced' and 'strict' currently apply the + same filtering on the backend; only 'lenient' differs by not + applying it. + :param sort_order: Default is as found in the input. Also allows 'longest' or 'shortest'. + :param disallowed_patterns: A pattern or JSON array of regex patterns to not include in the found codes. + :param include_multi_part_tokens: Whether to include multi-part tokens that have a space. Default True. + :param extract_raw: Whether to return tokens with their adjacent non-whitespace characters + included, rather than the cleaned token. Default False. + :return: A list of codes found. """ if isinstance(input, str): json_data = [input] diff --git a/wrangles/recipe_wrangles/extract.py b/wrangles/recipe_wrangles/extract.py index 60f63c92..5df75ad5 100644 --- a/wrangles/recipe_wrangles/extract.py +++ b/wrangles/recipe_wrangles/extract.py @@ -856,7 +856,7 @@ def codes( description: Maximum length of allowed results strategy: type: string - description: How aggressive to be at removing false positives such as measurements. + description: How aggressive to be at removing false positives such as measurements. Default is balanced. Note that balanced and strict currently apply the same filtering on the backend; only lenient differs by not applying it. enum: - lenient - balanced @@ -876,7 +876,7 @@ def codes( description: Whether to include multi-part tokens that have a space. Default True. extract_raw: type: boolean - description: Whether to return tokens with their adjacent non-whitespace characters. Default False. + description: Whether to return tokens with their adjacent non-whitespace characters included, rather than the cleaned token. Default False. """ # If output is not specified, overwrite input columns in place if output is None: output = input From 29bf189172ad0de1c5aa59221fb00d4f6221cf0a Mon Sep 17 00:00:00 2001 From: mborodii-prog Date: Wed, 24 Jun 2026 10:31:27 +0300 Subject: [PATCH 2/2] Align extract.codes docs with service strategy updates --- tests/recipes/wrangles/test_extract.py | 5 ++++- wrangles/extract.py | 7 +++---- wrangles/recipe_wrangles/extract.py | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/recipes/wrangles/test_extract.py b/tests/recipes/wrangles/test_extract.py index 9b0d4ea8..cfd46a9a 100644 --- a/tests/recipes/wrangles/test_extract.py +++ b/tests/recipes/wrangles/test_extract.py @@ -1058,7 +1058,10 @@ def test_extract_codes_wrong_params_sort(self): ) assert ( info.typename == 'ValueError' and - 'ERROR IN WRANGLE extract.codes - at line 3 - Status Code: 400 - Bad Request. {"message": "Invalid parameter sort_order. Expected longest or shortest."} \n' in info.value.args[0] + ( + 'ERROR IN WRANGLE extract.codes - at line 3 - Status Code: 400 - Bad Request. {"message": "Invalid parameter sort_order. Expected input, longest, or shortest."} \n' in info.value.args[0] + or 'ERROR IN WRANGLE extract.codes - at line 3 - Status Code: 400 - Bad Request. {"message": "Invalid parameter sort_order. Expected longest or shortest."} \n' in info.value.args[0] + ) ) diff --git a/wrangles/extract.py b/wrangles/extract.py index 3d526c3a..1f5c2717 100644 --- a/wrangles/extract.py +++ b/wrangles/extract.py @@ -433,10 +433,9 @@ def codes( :param max_length: Maximum length of allowed results. :param strategy: How aggressive to be at removing false positives such as measurements. One of 'lenient', 'balanced' or 'strict'. Default is - 'balanced'. Note that 'balanced' and 'strict' currently apply the - same filtering on the backend; only 'lenient' differs by not - applying it. - :param sort_order: Default is as found in the input. Also allows 'longest' or 'shortest'. + 'balanced'. Default minimum lengths are 3 for lenient, 4 for balanced, + and 5 for strict unless min_length is provided. + :param sort_order: Default is input order. Also allows 'longest' or 'shortest'. :param disallowed_patterns: A pattern or JSON array of regex patterns to not include in the found codes. :param include_multi_part_tokens: Whether to include multi-part tokens that have a space. Default True. :param extract_raw: Whether to return tokens with their adjacent non-whitespace characters diff --git a/wrangles/recipe_wrangles/extract.py b/wrangles/recipe_wrangles/extract.py index 5df75ad5..62b2712f 100644 --- a/wrangles/recipe_wrangles/extract.py +++ b/wrangles/recipe_wrangles/extract.py @@ -856,7 +856,7 @@ def codes( description: Maximum length of allowed results strategy: type: string - description: How aggressive to be at removing false positives such as measurements. Default is balanced. Note that balanced and strict currently apply the same filtering on the backend; only lenient differs by not applying it. + description: How aggressive to be at removing false positives such as measurements. Default is balanced. Default minimum lengths are 3 for lenient, 4 for balanced, and 5 for strict unless min_length is provided. enum: - lenient - balanced