Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed the behavior of None in to_strlist #915

Merged
merged 1 commit into from
Apr 25, 2024
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
2 changes: 1 addition & 1 deletion hed/tools/analysis/annotation_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def to_strlist(obj_list):
"""

# Using list comprehension to convert non-None items to strings
return [str(item) if item is not None else None for item in obj_list]
return [str(item) if item is not None else '' for item in obj_list]


def _flatten_cat_col(col_key, col_dict):
Expand Down
6 changes: 3 additions & 3 deletions tests/tools/analysis/test_annotation_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,19 +310,19 @@ def test_strs_to_tabular(self):
tab_in = str_to_tabular(events_contents, sidecar=self.json_path)
self.assertIsInstance(tab_in, TabularInput)

def test_convert_to_strlist(self):
def test_to_strlist(self):
# schema
# list1 = [HedString('Red, Sensory-event', schema)]
list1 = ['abc', '', None, 3.24]
str_list1 = to_strlist(list1)
self.assertEqual(len(str_list1), len(list1))
self.assertIsNone(str_list1[2], None)
self.assertFalse(str_list1[2])
self.assertEqual(str_list1[3], '3.24')
self.assertFalse(str_list1[1])
list2 = [HedString('Red, Sensory-event', self.hed_schema), None, HedString('', self.hed_schema)]
str_list2 = to_strlist(list2)
self.assertEqual(len(str_list2), len(list2))
self.assertIsNone(str_list2[1], None)
self.assertFalse(str_list2[1])
self.assertEqual(str_list2[0], 'Red,Sensory-event')
self.assertEqual(str_list2[2], '')

Expand Down
Loading