12
12
13
13
14
14
def project_exists (response , project ):
15
- ''' Checks if project exists on SAS Viya. If the project does not exist, then a new
15
+ """ Checks if project exists on SAS Viya. If the project does not exist, then a new
16
16
project is created or an error is raised.
17
17
18
18
Parameters
@@ -31,26 +31,26 @@ def project_exists(response, project):
31
31
------
32
32
SystemError
33
33
Alerts user that API calls cannot continue until a valid project is provided.
34
- '''
34
+ """
35
35
if response is None :
36
36
try :
37
- warn (' No project with the name or UUID {} was found.' .format (project ))
37
+ warn (" No project with the name or UUID {} was found." .format (project ))
38
38
UUID (project )
39
39
raise SystemError (
40
- ' The provided UUID does not match any projects found in SAS Model Manager. '
41
- + ' Please enter a valid UUID or a new name for a project to be created.'
40
+ " The provided UUID does not match any projects found in SAS Model Manager. "
41
+ + " Please enter a valid UUID or a new name for a project to be created."
42
42
)
43
43
except ValueError :
44
- repo = mr .default_repository ().get ('id' )
44
+ repo = mr .default_repository ().get ("id" )
45
45
response = mr .create_project (project , repo )
46
- print (' A new project named {} was created.' .format (response .name ))
46
+ print (" A new project named {} was created." .format (response .name ))
47
47
return response
48
48
else :
49
49
return response
50
50
51
51
52
52
def model_exists (project , name , force ):
53
- ''' Checks if model already exists and either raises an error or deletes the redundant model.
53
+ """ Checks if model already exists and either raises an error or deletes the redundant model.
54
54
55
55
Parameters
56
56
----------
@@ -66,30 +66,30 @@ def model_exists(project, name, force):
66
66
ValueError
67
67
Model repository API cannot overwrite an already existing model with the upload model call.
68
68
Alerts user of the force argument to allow multi-call API overwriting.
69
- '''
69
+ """
70
70
project = mr .get_project (project )
71
- projectId = project ['id' ]
72
- projectModels = mr .get (' /projects/{}/models' .format (projectId ))
71
+ projectId = project ["id" ]
72
+ projectModels = mr .get (" /projects/{}/models" .format (projectId ))
73
73
74
74
for model in projectModels :
75
75
# Throws a TypeError if only one model is in the project
76
76
try :
77
- if model [' name' ] == name :
77
+ if model [" name" ] == name :
78
78
if force :
79
79
mr .delete_model (model .id )
80
80
else :
81
81
raise ValueError (
82
- ' A model with the same model name exists in project {}. Include the force=True argument to overwrite models with the same name.' .format (
82
+ " A model with the same model name exists in project {}. Include the force=True argument to overwrite models with the same name." .format (
83
83
project .name
84
84
)
85
85
)
86
86
except TypeError :
87
- if projectModels [' name' ] == name :
87
+ if projectModels [" name" ] == name :
88
88
if force :
89
89
mr .delete_model (projectModels .id )
90
90
else :
91
91
raise ValueError (
92
- ' A model with the same model name exists in project {}. Include the force=True argument to overwrite models with the same name.' .format (
92
+ " A model with the same model name exists in project {}. Include the force=True argument to overwrite models with the same name." .format (
93
93
project .name
94
94
)
95
95
)
@@ -105,7 +105,7 @@ def pzmmImportModel(
105
105
inputDF ,
106
106
targetDF ,
107
107
predictmethod ,
108
- metrics = [' EM_EVENTPROBABILITY' , ' EM_CLASSIFICATION' ],
108
+ metrics = [" EM_EVENTPROBABILITY" , " EM_CLASSIFICATION" ],
109
109
modelFileName = None ,
110
110
pyPath = None ,
111
111
threshPrediction = None ,
@@ -114,7 +114,7 @@ def pzmmImportModel(
114
114
force = False ,
115
115
binaryString = None ,
116
116
):
117
- ''' Import model to SAS Model Manager using pzmm submodule.
117
+ """ Import model to SAS Model Manager using pzmm submodule.
118
118
119
119
Using pzmm, generate Python score code and import the model files into
120
120
SAS Model Manager. This function automatically checks the version of SAS
@@ -172,7 +172,7 @@ def pzmmImportModel(
172
172
Sets whether to overwrite models with the same name upon upload. By default False.
173
173
binaryString : string, optional
174
174
Binary string representation of the model object. By default None.
175
- '''
175
+ """
176
176
# Initialize no score code or binary H2O model flags
177
177
noScoreCode = False
178
178
binaryModel = False
@@ -192,36 +192,36 @@ def getFiles(extensions):
192
192
# If the model file name is not provided, set a default value depending on H2O and binary model status
193
193
if modelFileName is None :
194
194
if isH2OModel :
195
- binaryOrMOJO = getFiles ([' *.mojo' , ' *.pickle' ])
195
+ binaryOrMOJO = getFiles ([" *.mojo" , " *.pickle" ])
196
196
if len (binaryOrMOJO ) == 0 :
197
197
print (
198
- ' WARNING: An H2O model file was not found at {}. Score code will not be automatically generated.' .format (
198
+ " WARNING: An H2O model file was not found at {}. Score code will not be automatically generated." .format (
199
199
str (pyPath )
200
200
)
201
201
)
202
202
noScoreCode = True
203
203
elif len (binaryOrMOJO ) == 1 :
204
- if str (binaryOrMOJO [0 ]).endswith (' .pickle' ):
204
+ if str (binaryOrMOJO [0 ]).endswith (" .pickle" ):
205
205
binaryModel = True
206
- modelFileName = modelPrefix + ' .pickle'
206
+ modelFileName = modelPrefix + " .pickle"
207
207
else :
208
- modelFileName = modelPrefix + ' .mojo'
208
+ modelFileName = modelPrefix + " .mojo"
209
209
else :
210
210
print (
211
- ' WARNING: Both a MOJO and binary model file are present at {}. Score code will not be automatically generated.' .format (
211
+ " WARNING: Both a MOJO and binary model file are present at {}. Score code will not be automatically generated." .format (
212
212
str (pyPath )
213
213
)
214
214
)
215
215
noScoreCode = True
216
216
else :
217
- modelFileName = modelPrefix + ' .pickle'
217
+ modelFileName = modelPrefix + " .pickle"
218
218
219
219
# Check the SAS Viya version number being used
220
- isViya35 = platform_version () == ' 3.5'
220
+ isViya35 = platform_version () == " 3.5"
221
221
# For SAS Viya 4, the score code can be written beforehand and imported with all of the model files
222
222
if not isViya35 :
223
223
if noScoreCode :
224
- print (' No score code was generated.' )
224
+ print (" No score code was generated." )
225
225
else :
226
226
sc .writeScoreCode (
227
227
inputDF ,
@@ -238,12 +238,12 @@ def getFiles(extensions):
238
238
binaryString = binaryString ,
239
239
)
240
240
print (
241
- ' Model score code was written successfully to {}.' .format (
242
- Path (pyPath ) / (modelPrefix + ' Score.py' )
241
+ " Model score code was written successfully to {}." .format (
242
+ Path (pyPath ) / (modelPrefix + " Score.py" )
243
243
)
244
244
)
245
245
zipIOFile = zm .zipFiles (Path (zPath ), modelPrefix )
246
- print (' All model files were zipped to {}.' .format (Path (zPath )))
246
+ print (" All model files were zipped to {}." .format (Path (zPath )))
247
247
248
248
# Check if project name provided exists and raise an error or create a new project
249
249
projectResponse = mr .get_project (project )
@@ -255,16 +255,16 @@ def getFiles(extensions):
255
255
response = mr .import_model_from_zip (modelPrefix , project , zipIOFile )
256
256
try :
257
257
print (
258
- ' Model was successfully imported into SAS Model Manager as {} with UUID: {}.' .format (
258
+ " Model was successfully imported into SAS Model Manager as {} with UUID: {}." .format (
259
259
response .name , response .id
260
260
)
261
261
)
262
262
except AttributeError :
263
- print (' Model failed to import to SAS Model Manager.' )
263
+ print (" Model failed to import to SAS Model Manager." )
264
264
# For SAS Viya 3.5, the score code is written after upload in order to know the model UUID
265
265
else :
266
266
zipIOFile = zm .zipFiles (Path (zPath ), modelPrefix )
267
- print (' All model files were zipped to {}.' .format (Path (zPath )))
267
+ print (" All model files were zipped to {}." .format (Path (zPath )))
268
268
269
269
# Check if project name provided exists and raise an error or create a new project
270
270
projectResponse = mr .get_project (project )
@@ -276,14 +276,14 @@ def getFiles(extensions):
276
276
response = mr .import_model_from_zip (modelPrefix , project , zipIOFile , force )
277
277
try :
278
278
print (
279
- ' Model was successfully imported into SAS Model Manager as {} with UUID: {}.' .format (
279
+ " Model was successfully imported into SAS Model Manager as {} with UUID: {}." .format (
280
280
response .name , response .id
281
281
)
282
282
)
283
283
except AttributeError :
284
- print (' Model failed to import to SAS Model Manager.' )
284
+ print (" Model failed to import to SAS Model Manager." )
285
285
if noScoreCode :
286
- print (' No score code was generated.' )
286
+ print (" No score code was generated." )
287
287
else :
288
288
sc .writeScoreCode (
289
289
inputDF ,
@@ -301,7 +301,7 @@ def getFiles(extensions):
301
301
binaryString = binaryString ,
302
302
)
303
303
print (
304
- ' Model score code was written successfully to {} and uploaded to SAS Model Manager' .format (
305
- Path (pyPath ) / (modelPrefix + ' Score.py' )
304
+ " Model score code was written successfully to {} and uploaded to SAS Model Manager" .format (
305
+ Path (pyPath ) / (modelPrefix + " Score.py" )
306
306
)
307
307
)
0 commit comments