From e79cc513a42026f0143b339da58e7b2b7da886d8 Mon Sep 17 00:00:00 2001 From: Synchon Mandal Date: Fri, 5 Apr 2024 13:51:16 +0200 Subject: [PATCH 1/2] fix: force element parsing from file to be str and add missing tests --- junifer/api/cli.py | 7 +++---- junifer/api/tests/test_cli.py | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) 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( -- 2.52.0 From c284d761d2a9b05fe84c8b80b1d3136a124e165e Mon Sep 17 00:00:00 2001 From: Synchon Mandal Date: Fri, 5 Apr 2024 15:10:02 +0200 Subject: [PATCH 2/2] chore: add changelog 322.bugfix --- docs/changes/newsfragments/322.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 docs/changes/newsfragments/322.bugfix 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`_ -- 2.52.0