2525
2626
2727def _sklearn_to_dict (model ):
28+ # As of Viya 3.4 model registration fails if character fields are longer
29+ # than 1024 characters
30+ DESC_MAXLEN = 1024
31+
32+ # As of Viya 3.4 model registration fails if user-defined properties are
33+ # longer than 512 characters.
34+ PROP_MAXLEN = 512
35+
2836 # Convert Scikit-learn values to built-in Model Manager values
2937 mappings = {'LogisticRegression' : 'Logistic regression' ,
3038 'LinearRegression' : 'Linear regression' ,
3139 'SVC' : 'Support vector machine' ,
3240 'GradientBoostingClassifier' : 'Gradient boosting' ,
41+ 'XGBClassifier' : 'Gradient boosting' ,
42+ 'XGBRegressor' : 'Gradient boosting' ,
3343 'RandomForestClassifier' : 'Forest' ,
3444 'DecisionTreeClassifier' : 'Decision tree' ,
3545 'DecisionTreeRegressor' : 'Decision tree' ,
3646 'classifier' : 'Classification' ,
3747 'regressor' : 'Prediction' }
3848
49+ if hasattr (model , '_final_estimator' ):
50+ estimator = type (model ._final_estimator )
51+ else :
52+ estimator = type (model )
53+
3954 # Can tell if multi-class .multi_class
4055 result = dict (
41- description = str (model ),
42- algorithm = mappings .get (type ( model ) .__name__ , type ( model ) .__name__ ),
56+ description = str (model )[: DESC_MAXLEN ] ,
57+ algorithm = mappings .get (estimator .__name__ , estimator .__name__ ),
4358 scoreCodeType = 'ds2MultiType' ,
4459 trainCodeType = 'Python' ,
4560 function = mappings .get (model ._estimator_type , model ._estimator_type ),
4661 tool = 'Python %s.%s'
4762 % (sys .version_info .major , sys .version_info .minor ),
48- properties = [{'name' : k , 'value' : v }
63+ properties = [{'name' : str (k )[:PROP_MAXLEN ],
64+ 'value' : str (v )[:PROP_MAXLEN ]}
4965 for k , v in model .get_params ().items ()]
5066 )
5167
@@ -156,9 +172,9 @@ def register_model(model, name, project, repository=None, input=None,
156172 files .append ({'name' : 'dmcas_packagescorecode.sas' ,
157173 'file' : mas_module .score_code (),
158174 'role' : 'Score Code' })
159- files .append ({'name' : 'dmcas_espscorecode .sas' ,
160- 'file' : mas_module .score_code (dest = 'ESP ' ),
161- 'role' : 'Score Code ' })
175+ files .append ({'name' : 'dmcas_epscorecode .sas' ,
176+ 'file' : mas_module .score_code (dest = 'CAS ' ),
177+ 'role' : 'score ' })
162178
163179 model ['inputVariables' ] = [var .as_model_metadata ()
164180 for var in mas_module .variables
@@ -203,7 +219,10 @@ def register_model(model, name, project, repository=None, input=None,
203219 return model
204220
205221
206- def publish_model (model , destination , code = None , max_retries = 60 ,
222+ def publish_model (model ,
223+ destination ,
224+ code = None ,
225+ max_retries = 60 ,
207226 replace = False , ** kwargs ):
208227 """Publish a model to a configured publishing destination.
209228
@@ -248,7 +267,15 @@ def publish_model(model, destination, code=None, max_retries=60,
248267 def submit_request ():
249268 # Submit a publishing request
250269 if code is None :
251- publish_req = mm .publish_model (model , destination , ** kwargs )
270+ dest_obj = mp .get_destination (destination )
271+
272+ if dest_obj and dest_obj .destinationType == "cas" :
273+ publish_req = mm .publish_model (model , destination ,
274+ force = replace ,
275+ reload_model_table = True )
276+ else :
277+ publish_req = mm .publish_model (model , destination ,
278+ force = replace )
252279 else :
253280 publish_req = mp .publish_model (model , destination ,
254281 code = code , ** kwargs )
@@ -262,6 +289,11 @@ def submit_request():
262289 # Submit and wait for status
263290 job = submit_request ()
264291
292+ # If model was successfully published and it isn't a MAS module, we're done
293+ if job .state .lower () == 'completed' \
294+ and job .destination .destinationType != 'microAnalyticService' :
295+ return request_link (job ,'self' )
296+
265297 # If MAS publish failed and replace=True, attempt to delete the module
266298 # and republish
267299 if job .state .lower () == 'failed' and replace and \
0 commit comments