orhankislal commented on a change in pull request #359: DL: Remove eval
statement
URL: https://github.com/apache/madlib/pull/359#discussion_r270603485
##########
File path: src/ports/postgres/modules/deep_learning/madlib_keras_wrapper.py_in
##########
@@ -85,7 +96,57 @@ def convert_string_of_args_to_dict(str_of_args):
stack.pop(-1)
result_str += char
elif not stack and char == "=":
- result_str += ":"
+ key_str = result_str
+ result_str = ""
+ elif not stack and char == ",":
+ value_str = result_str
+ result_str = ""
+ compile_dict[key_str.strip()]=value_str.strip('\'')
else:
result_str += char
- return eval('{' + result_str + '}')
+ value_str = result_str
+ result_str = ""
+ compile_dict[key_str.strip()]=value_str.strip('\'')
+ return compile_dict
+
+
+# Parse the compile parameters and the optimizer.
+# Optimizer name and its arguments are returned in addition to the rest of the
+# compile parameters.
+def parse_compile_params(str_of_args):
+
+ compile_dict = convert_string_of_args_to_dict(str_of_args)
+ compile_dict['metrics'] = ast.literal_eval(compile_dict['metrics']) if
'metrics' in compile_dict.keys() else None
Review comment:
Since a string is not accepted by ast.literal_eval, it will throw an error.
If the input is "['rm -rf /.']" then it will be passed as a string array to the
keras. Then keras will throw its own error saying this is not a valid input for
metrics.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services