@@ -58,11 +58,25 @@ def build_wrapper_function(func, variables, array_input, setup=None,
58
58
args = input_names
59
59
func = func .__name__ if callable (func ) else func
60
60
61
+ # HELPER: SAS to python char issue where SAS char have spaces and python string does not.
62
+ # NOTE: we assume SAS char always need white space to be trimmed. This seems to match python model built so far
63
+ pythonStringInput = ('' ,)
64
+ for tmp1 in variables :
65
+ if not tmp1 .out :
66
+ if tmp1 .type == 'char' :
67
+ pythonStringInput = pythonStringInput + (" if " + tmp1 .name + ": " + tmp1 .name + " = " + tmp1 .name + ".strip()" ,)
68
+
61
69
# Statement to execute the function w/ provided parameters
62
70
if array_input :
63
- func_call = '{}(np.array([{}]).reshape((1, -1)))' .format (func , ',' .join (args ))
71
+ middle = pythonStringInput + \
72
+ (' inputarray = np.array([{}]).reshape((1, -1))' .format (',' .join (args )),
73
+ ' column=[{}]' .format (',' .join ('"{0}"' .format (w ) for w in args )),
74
+ ' import pandas as pd' ,
75
+ ' inputrun=pd.DataFrame(data=inputarray, columns=column)' ,
76
+ ' result = {}(inputrun)' .format (func ))
64
77
else :
65
78
func_call = '{}({})' .format (func , ',' .join (args ))
79
+ middle = (' result = {}' .format (func_call ))
66
80
67
81
# TODO: Verify that # of values returned by wrapped func matches length of output_names
68
82
# TODO: cast all return types before returning (DS2 errors out if not exact match)
@@ -80,6 +94,7 @@ def build_wrapper_function(func, variables, array_input, setup=None,
80
94
else :
81
95
header = ('' , )
82
96
97
+
83
98
definition = header + \
84
99
('def wrapper({}):' .format (', ' .join (args )),
85
100
' "Output: {}"' .format (', ' .join (output_names + ['msg' ]) if return_msg
@@ -90,9 +105,9 @@ def build_wrapper_function(func, variables, array_input, setup=None,
90
105
' if _compile_error is not None:' ,
91
106
' raise _compile_error' ,
92
107
' msg = ""' if return_msg else '' ,
93
- ' import numpy as np' ,
94
- ' result = {}' . format ( func_call ),
95
- ' if result.size == 1:' ,
108
+ ' import numpy as np' ) + \
109
+ middle + \
110
+ ( ' if result.size == 1:' ,
96
111
' result = np.asscalar(result)' ,
97
112
' except Exception as e:' ,
98
113
' msg = str(e)' if return_msg else '' ,
@@ -103,6 +118,7 @@ def build_wrapper_function(func, variables, array_input, setup=None,
103
118
' else: ' ,
104
119
' return result, msg' )
105
120
121
+
106
122
return '\n ' .join (definition )
107
123
108
124
0 commit comments