From 9d328534aa272d8b4f8cfe77d30117f980794a8a Mon Sep 17 00:00:00 2001 From: Michael Ou Date: Wed, 23 Nov 2022 10:29:32 -0500 Subject: [PATCH] fixBug: not reading comma separated data correctly (#1634) * fixBug: not reading comma separated data correctly To test: ```python from flopy.utils.datautil import PyListUtil line = '13,14' ``` PyListUtil.split_data_line(line) * test(PyListUtil): add minimal test for split_data_line() Co-authored-by: w-bonelli --- .gitignore | 2 ++ autotest/test_datautil.py | 14 ++++++++++++-- flopy/utils/datautil.py | 1 + 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index f49509acda..b12674425a 100644 --- a/.gitignore +++ b/.gitignore @@ -91,3 +91,5 @@ autotest/.noseids .docs/_notebooks *.bak + +**.env diff --git a/autotest/test_datautil.py b/autotest/test_datautil.py index 2f789b86bc..d4a735a289 100644 --- a/autotest/test_datautil.py +++ b/autotest/test_datautil.py @@ -1,3 +1,13 @@ +from flopy.utils.datautil import PyListUtil + + def test_split_data_line(): - # TODO: try to reproduce this: https://github.com/modflowpy/flopy/runs/7581629193?check_suite_focus=true#step:11:1753 - pass + # fixes: https://github.com/modflowpy/flopy/runs/7581629193?check_suite_focus=true#step:11:1753 + + line = "13,14,15, 16, 17," + spl = PyListUtil.split_data_line(line) + exp = ["13", "14", "15", "16", "17"] + assert len(spl) == len(exp) + # whitespace is not removed, todo: can it be? + # or is it needed to support Modflow input file format? + assert all(any([e in s for s in spl]) for e in exp) diff --git a/flopy/utils/datautil.py b/flopy/utils/datautil.py index e57a5161d9..702e2c177b 100644 --- a/flopy/utils/datautil.py +++ b/flopy/utils/datautil.py @@ -329,6 +329,7 @@ def split_data_line(line, external_file=False, delimiter_conf_length=15): if alt_split_len > max_split_size: max_split_size = len(alt_split) max_split_type = delimiter + max_split_list = alt_split elif alt_split_len == max_split_size: if ( max_split_type not in PyListUtil.delimiter_list