Skip to content

Commit

Permalink
changed misc_utils.to_enum to not be fuzzy match by default for struc…
Browse files Browse the repository at this point in the history
…tured_data/smaht-submitr
  • Loading branch information
dmichaels-harvard committed Aug 8, 2024
1 parent 234ea04 commit 83e1214
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Change Log
* Changes in structured_data.py for validator hook.
* Added to_number function to misc_utils.
* Added run_concurrently function to misc_utils.
* Changed misc_utils.to_enum to default to non-fuzzy (prefix) match, for structured_data,
i.e for smaht-submitr to match on (case-insensitive) full enum namess.


8.13.3
Expand Down
4 changes: 3 additions & 1 deletion dcicutils/misc_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1105,12 +1105,14 @@ def to_boolean(value: str, fallback: Optional[Any]) -> Optional[Any]:
return fallback


def to_enum(value: str, enumerators: List[str]) -> Optional[str]:
def to_enum(value: str, enumerators: List[str], fuzzy: bool = False) -> Optional[str]:
matches = []
if isinstance(value, str) and (value := value.strip()) and isinstance(enumerators, List):
enum_specifiers = {str(enum).lower(): enum for enum in enumerators}
if (enum_value := enum_specifiers.get(lower_value := value.lower())) is not None:
return enum_value
if fuzzy is not True:
return value
for enum_canonical, _ in enum_specifiers.items():
if enum_canonical.startswith(lower_value):
matches.append(enum_canonical)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "dcicutils"
version = "8.13.3.1b24" # TODO: To become 8.14.0
version = "8.13.3.1b25" # TODO: To become 8.14.0
description = "Utility package for interacting with the 4DN Data Portal and other 4DN resources"
authors = ["4DN-DCIC Team <[email protected]>"]
license = "MIT"
Expand Down
Binary file not shown.

0 comments on commit 83e1214

Please sign in to comment.