-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move an IDW helper into a new module, as it's not specifically YAML-r…
…elated
- Loading branch information
1 parent
ea4a533
commit 8691600
Showing
2 changed files
with
45 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
"""Helpers for use in the IDW profile.""" | ||
|
||
from typing import Any, Dict, List, Union | ||
|
||
|
||
def replace_micrometer_values( | ||
data: Union[Dict[Any, Any], List[Any]], replacement: str | ||
) -> Union[Dict[Any, Any], List[Any]]: | ||
"""Recursively replace micrometer values in a dictionary or list. | ||
This function searches for string values in dictionaries or lists that end with "µm" | ||
(micrometers) and replaces them with the specified replacement string. | ||
Args: | ||
data (Union[Dict, List]): The dictionary or list containing values to check and replace. | ||
replacement (str): The replacement string for micrometer values. | ||
Returns: | ||
Union[Dict, List]: The input data with micrometer values replaced. | ||
""" | ||
if isinstance(data, dict): | ||
for key, value in data.items(): | ||
data[key] = ( | ||
replace_micrometer_values(value, replacement) | ||
if isinstance(value, (dict, list)) | ||
else ( | ||
value[:-2] + replacement | ||
if isinstance(value, str) and value.endswith("µm") | ||
else value | ||
) | ||
) | ||
elif isinstance(data, list): | ||
return [ | ||
( | ||
replace_micrometer_values(item, replacement) | ||
if isinstance(item, (dict, list)) | ||
else ( | ||
item[:-2] + replacement | ||
if isinstance(item, str) and item.endswith("µm") | ||
else item | ||
) | ||
) | ||
for item in data | ||
] | ||
return data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters