Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion tests/recipes/wrangles/test_extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
)
)


Expand Down
14 changes: 14 additions & 0 deletions wrangles/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,20 @@ 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'. 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
included, rather than the cleaned token. Default False.
:return: A list of codes found.
"""
if isinstance(input, str):
json_data = [input]
Expand Down
4 changes: 2 additions & 2 deletions wrangles/recipe_wrangles/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -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. Default minimum lengths are 3 for lenient, 4 for balanced, and 5 for strict unless min_length is provided.
enum:
- lenient
- balanced
Expand All @@ -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
Expand Down