diff --git a/docs/changes/newsfragments/322.bugfix b/docs/changes/newsfragments/322.bugfix new file mode 100644 index 000000000..462166332 --- /dev/null +++ b/docs/changes/newsfragments/322.bugfix @@ -0,0 +1 @@ +Force ``str`` dtype when parsing elements from file by `Synchon Mandal`_ diff --git a/junifer/api/cli.py b/junifer/api/cli.py index e6a10a2c5..9c0364215 100644 --- a/junifer/api/cli.py +++ b/junifer/api/cli.py @@ -114,14 +114,13 @@ def _parse_elements_file(filepath: Path) -> List[Tuple[str, ...]]: filepath, header=None, # no header # type: ignore index_col=False, # no index column + dtype=str, skipinitialspace=True, # no leading space after delimiter ) # Remove trailing whitespace in cell entries - csv_df_trimmed = csv_df.apply( - lambda x: x.str.strip() if x.dtype == "object" else x - ) + csv_df_trimmed = csv_df.apply(lambda x: x.str.strip()) # Convert to list of tuple of str - return list(map(tuple, csv_df_trimmed.to_numpy().astype(str))) + return list(map(tuple, csv_df_trimmed.to_numpy())) def _validate_verbose( diff --git a/junifer/api/tests/test_cli.py b/junifer/api/tests/test_cli.py index 4efd8c912..5ad159b71 100644 --- a/junifer/api/tests/test_cli.py +++ b/junifer/api/tests/test_cli.py @@ -156,6 +156,21 @@ def test_run_using_element_file(tmp_path: Path, elements: str) -> None: " sub-01 , ses-01 \n sub-02, ses-01 ", [("sub-01", "ses-01"), ("sub-02", "ses-01")], ), + ("001,01", [("001", "01")]), + ( + "001,01\n002,02", + [("001", "01"), ("002", "02")], + ), + ("001, 01", [("001", "01")]), + ( + "001, 01\n002, 02", + [("001", "01"), ("002", "02")], + ), + (" 001 , 01 ", [("001", "01")]), + ( + " 001 , 01 \n 002, 02 ", + [("001", "01"), ("002", "02")], + ), ], ) def test_multi_element_access(