Merged in hotfix/flatten-list-to-string (pull request #478)

Hotfix/flatten list to string

* updated
* rate fields fix
* updated the singleton_list
* updated
* added
* Checked_files

* added

* Merged main into hotfix/flatten-list-to-string

* format_rate_fields_with_commas

* Update test

* flatten_singleton_string_list - new cases

* Update

* Removed unneccessary case

* Remove case

* Updated the test cases
* Merge remote-tracking branch 'origin/main' into hotfix/flatten-list-to-string

* Refactor flatten_singleton_string_list to handle empty input and return a comma-separated string for multiple elements


Approved-by: Katon Minhas
This commit is contained in:
Alex Galarce
2025-04-16 17:42:51 +00:00
parent 2700fa2c9c
commit 54910a7459
2 changed files with 8 additions and 5 deletions
@@ -74,12 +74,14 @@ def flatten_singleton_string_list(list_str: str) -> str:
Returns:
str: The single element if the list has one element, otherwise the list as a string.
"""
if string_utils.is_empty(list_str):
return ""
try:
# Convert the string to a list using ast.literal_eval
list_obj = ast.literal_eval(list_str)
if len(list_obj) == 1:
return list_obj[0]
return list_obj
return ", ".join(list_obj)
except (ValueError, SyntaxError):
return list_str
@@ -25,10 +25,11 @@ class TestPostprocessFunctions(unittest.TestCase):
self.assertEqual(normalize_indicator_field(None), "N")
def test_format_rate_fields_with_commas(self):
# Test numeric values
self.assertEqual(format_rate_fields_with_commas("1234.567"), "1,234.57")
self.assertEqual(format_rate_fields_with_commas("1000"), "1,000.00")
self.assertEqual(format_rate_fields_with_commas("abc"), "0.00")
self.assertEqual(format_rate_fields_with_commas(None), "0.00")
self.assertEqual(format_rate_fields_with_commas(1234.567), "1,234.57")
self.assertEqual(format_rate_fields_with_commas(1000), "1,000.00")
def test_remove_hyphens(self):
self.assertEqual(remove_hyphens("123-45-6789"), "123456789")
@@ -38,9 +39,9 @@ class TestPostprocessFunctions(unittest.TestCase):
def test_flatten_singleton_string_list(self):
self.assertEqual(flatten_singleton_string_list("['123']"), "123")
self.assertEqual(flatten_singleton_string_list("['123', '456']"), ['123', '456'])
self.assertEqual(flatten_singleton_string_list("['123', '456']"), "123, 456")
self.assertEqual(flatten_singleton_string_list("invalid"), "invalid")
self.assertEqual(flatten_singleton_string_list(None), None)
self.assertEqual(flatten_singleton_string_list(None), "")
@patch("src.utils.llm_utils.invoke_claude")