-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dd_to_csv bugfixes, move cache to ~/.cache/xl2times/
#230
Changes from 11 commits
bab423c
582d79b
fd01005
86a1480
af8aa79
3b8719b
7bcffc8
1615397
a2bba6e
0262d97
0c767ff
e53cef1
5c5c8bf
56f333f
bb2a536
95ec59f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,20 +53,19 @@ def parse_parameter_values_from_file( | |
param_data = [] | ||
# Parse values until a line with / is encountered. | ||
while not data[index].startswith("/") and data[index] != "": | ||
words = data[index].split(" ") | ||
line = data[index] | ||
|
||
# Either "value" for a scalar, or "key value" for an array. | ||
if len(words) == 1: | ||
attributes = [] | ||
elif len(words) == 2: | ||
attributes = words[0].split(".") | ||
attributes = [a if " " in a else a.strip("'") for a in attributes] | ||
# So value is always the last word, or only token | ||
split_point = line.rfind(" ") | ||
if split_point == -1: | ||
# if only one word | ||
attributes, value = [], line | ||
else: | ||
raise ValueError( | ||
f"Unexpected number of spaces in parameter value setting: {data[index]}" | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This ValueError was getting thrown from veda-produced austimes DD files for a variable with a space in its name There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @SamRWest when you write "variable" do you mean an index of a GAMS parameter or a GAMS parameter? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, 'variable' is the wrong terminology. I mean the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For example, here's a line from one of our DD files that (i think) would have triggered the ValueError, because of the spaces in
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see, thanks! It should be okay not to raise There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool, that was my assumption. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Btw, sometimes there is no value, e.g. from Demo 1:
Let's say somebody does this:
What will happen? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I can see we are handling this above when we check whether it is a parameter. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, the new code will catch this with this check, because if split_point == -1:
#if only one word
attributes, value = [], line |
||
attributes, value = line[:split_point], line[split_point + 1 :] | ||
attributes = attributes.split(".") | ||
attributes = [a if " " in a else a.strip("'") for a in attributes] | ||
Comment on lines
+59
to
+67
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
|
||
value = words[-1] | ||
param_data.append([*attributes, value]) | ||
|
||
index += 1 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about this @siddharth-krishna ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks!