Skip to content

Commit

Permalink
Merge pull request #308 from JamesPHoughton/bug
Browse files Browse the repository at this point in the history
Solve bug of line breaks in arrays
  • Loading branch information
enekomartinmartinez authored Feb 7, 2022
2 parents fc06a12 + 6099478 commit 04fc997
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pysd/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.2.0"
__version__ = "2.2.1"
5 changes: 3 additions & 2 deletions pysd/translation/vensim/vensim2py.py
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,7 @@ def parse_general_expression(element, namespace={}, subscript_dict={},
reference = (id _ subscript_list) / id # check first for subscript
subscript_list = "[" _ ~"\""? _ (subs _ ~"\""? _ "!"? _ ","? _)+ _ "]"
array = (number _ ("," / ";")? _)+ !~r"." # negative lookahead for
array = (number _ ("," / ";")? _ "\\"? _)+ !~r"." # negative lookahead for
# anything other than an array
string = "\'" ( "\\\'" / ~r"[^\']"IU )* "\'"
Expand Down Expand Up @@ -1368,7 +1368,8 @@ def visit_array(self, n, vc):
element["subs"], subscript_dict, terse=False
)
if ";" in n.text or "," in n.text:
text = n.text.strip(";").replace(" ", "").replace(";", ",")
text = n.text.strip(";").replace(" ", "").replace(
";", ",").replace("\\", "")
data = np.array([float(s) for s in text.split(",")])
data = data.reshape(compute_shape(coords))
datastr = (
Expand Down
4 changes: 4 additions & 0 deletions tests/integration_test_vensim_pathway.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ def test_arguments(self):
output, canon = runner(test_models + '/arguments/test_arguments.mdl')
assert_frames_close(output, canon, rtol=rtol)

def test_array_with_line_break(self):
output, canon = runner(test_models + '/array_with_line_break/test_array_with_line_break.mdl')
assert_frames_close(output, canon, rtol=rtol)

def test_builtin_max(self):
output, canon = runner(test_models + '/builtin_max/builtin_max.mdl')
assert_frames_close(output, canon, rtol=rtol)
Expand Down

0 comments on commit 04fc997

Please sign in to comment.