From 7174ac430d6652641f0be91720ae765d68d2ed29 Mon Sep 17 00:00:00 2001 From: "Walter.Kolczynski" Date: Tue, 30 Jul 2024 21:37:07 -0500 Subject: [PATCH] Remove empty elements from comma-separated list Updates the list parsing in Configuration to remove empty strings from the comma-separated list. This will allow creating a single- element list by appending a `,` after the element. Refs: NOAA-EMC/global-workflow#2795 --- src/wxflow/configuration.py | 2 +- tests/test_configuration.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wxflow/configuration.py b/src/wxflow/configuration.py index f06a3f3..3f9319b 100644 --- a/src/wxflow/configuration.py +++ b/src/wxflow/configuration.py @@ -172,7 +172,7 @@ def cast_as_dtype(string: str) -> Union[str, int, float, bool, Any]: if ',' in string: # Convert comma-separated list to python list - return [cast_as_dtype(elem.strip()) for elem in string.split(',')] + return [cast_as_dtype(elem.strip()) for elem in string.split(',') if elem.strip() != ''] def _cast_or_not(to_type: Any, string: str): try: diff --git a/tests/test_configuration.py b/tests/test_configuration.py index 1070226..077b00a 100644 --- a/tests/test_configuration.py +++ b/tests/test_configuration.py @@ -32,7 +32,7 @@ export SOME_BOOL6=.F. export SOME_LIST1="3, 15, -999" export SOME_LIST2="0.2,3.5,-9999." -export SOME_LIST3="20221225, 202212251845" +export SOME_LIST3="20221225, 202212251845," export SOME_LIST4="YES, .false., .T." export SOME_LIST5="0.2, test_str, 15, 20221225, NO" """