20
20
swat = None
21
21
22
22
23
- def create_package (table ):
23
+ def create_package (table , input = None ):
24
24
"""Create an importable model package from a CAS table.
25
25
26
26
Parameters
27
27
----------
28
28
table : swat.CASTable
29
29
The CAS table containing an ASTORE or score code.
30
+ input : DataFrame, type, list of type, or dict of str: type, optional
31
+ The expected type for each input value of the target function.
32
+ Can be omitted if target function includes type hints. If a DataFrame
33
+ is provided, the columns will be inspected to determine type information.
34
+ If a single type is provided, all columns will be assumed to be that type,
35
+ otherwise a list of column types or a dictionary of column_name: type
36
+ may be provided.
37
+
30
38
31
39
Returns
32
40
-------
@@ -45,18 +53,26 @@ def create_package(table):
45
53
assert isinstance (table , swat .CASTable )
46
54
47
55
if 'DataStepSrc' in table .columns :
48
- return create_package_from_datastep (table )
56
+ #Input only passed to datastep
57
+ return create_package_from_datastep (table , input = input )
49
58
else :
50
59
return create_package_from_astore (table )
51
60
52
61
53
- def create_package_from_datastep (table ):
62
+ def create_package_from_datastep (table , input = None ):
54
63
"""Create an importable model package from a score code table.
55
64
56
65
Parameters
57
66
----------
58
67
table : swat.CASTable
59
68
The CAS table containing the score code.
69
+ input : DataFrame, type, list of type, or dict of str: type, optional
70
+ The expected type for each input value of the target function.
71
+ Can be omitted if target function includes type hints. If a DataFrame
72
+ is provided, the columns will be inspected to determine type information.
73
+ If a single type is provided, all columns will be assumed to be that type,
74
+ otherwise a list of column types or a dictionary of column_name: type
75
+ may be provided.
60
76
61
77
Returns
62
78
-------
@@ -73,11 +89,41 @@ def create_package_from_datastep(table):
73
89
74
90
dscode = table .to_frame ().loc [0 , 'DataStepSrc' ]
75
91
92
+ #TODO: Extract inputs into file
93
+
94
+ #Find outputs from ds code
95
+ output_vars = []
96
+ for sasline in dscode .split ('\n ' ):
97
+ if sasline .strip ().startswith ('label' ):
98
+ output_var = dict ()
99
+ for tmp in sasline .split ('=' ):
100
+ if 'label' in tmp :
101
+ ovarname = tmp .split ('label' )[1 ].strip ()
102
+ output_var .update ({"name" :ovarname })
103
+ #Determine type of variable is decimal or string
104
+ if "length " + ovarname in dscode :
105
+ sastype = dscode .split ("length " + ovarname )[1 ].split (';' )[0 ].strip ()
106
+ if "$" in sastype :
107
+ output_var .update ({"type" :"string" })
108
+ output_var .update ({"length" :sastype .split ("$" )[1 ]})
109
+ else :
110
+ output_var .update ({"type" :"decimal" })
111
+ output_var .update ({"length" :sastype })
112
+ else :
113
+ #If no length for varaible, default is decimal, 8
114
+ output_var .update ({"type" :"decimal" })
115
+ output_var .update ({"length" :8 })
116
+ else :
117
+ output_var .update ({"description" :tmp .split (';' )[0 ].strip ().strip ("'" )})
118
+ output_vars .append (output_var )
119
+
76
120
file_metadata = [{'role' : 'score' , 'name' : 'dmcas_scorecode.sas' }]
77
121
78
122
zip_file = _build_zip_from_files ({
79
123
'fileMetadata.json' : file_metadata ,
80
- 'dmcas_scorecode.sas' : dscode
124
+ 'dmcas_scorecode.sas' : dscode ,
125
+ 'ModelProperties.json' : {"scoreCodeType" :"dataStep" },
126
+ 'outputVar.json' : output_vars
81
127
})
82
128
83
129
return zip_file
0 commit comments