29
29
30
30
logger = logging .getLogger (__name__ )
31
31
32
+ # As of Viya 3.4 model registration fails if character fields are longer
33
+ # than 1024 characters
34
+ _DESC_MAXLEN = 1024
32
35
33
- def _sklearn_to_dict (model ):
34
- # As of Viya 3.4 model registration fails if character fields are longer
35
- # than 1024 characters
36
- DESC_MAXLEN = 1024
36
+ # As of Viya 3.4 model registration fails if user-defined properties are
37
+ # longer than 512 characters.
38
+ _PROP_MAXLEN = 512
37
39
38
- # As of Viya 3.4 model registration fails if user-defined properties are
39
- # longer than 512 characters.
40
- PROP_MAXLEN = 512
41
40
41
+ def _sklearn_to_dict (model ):
42
42
# Convert Scikit-learn values to built-in Model Manager values
43
43
mappings = {'LogisticRegression' : 'Logistic regression' ,
44
44
'LinearRegression' : 'Linear regression' ,
@@ -59,15 +59,15 @@ def _sklearn_to_dict(model):
59
59
60
60
# Can tell if multi-class .multi_class
61
61
result = dict (
62
- description = str (model )[:DESC_MAXLEN ],
62
+ description = str (model )[:_DESC_MAXLEN ],
63
63
algorithm = mappings .get (estimator .__name__ , estimator .__name__ ),
64
64
scoreCodeType = 'ds2MultiType' ,
65
65
trainCodeType = 'Python' ,
66
66
function = mappings .get (model ._estimator_type , model ._estimator_type ),
67
67
tool = 'Python %s.%s'
68
68
% (sys .version_info .major , sys .version_info .minor ),
69
- properties = [{'name' : str (k )[:PROP_MAXLEN ],
70
- 'value' : str (v )[:PROP_MAXLEN ]}
69
+ properties = [{'name' : str (k )[:_PROP_MAXLEN ],
70
+ 'value' : str (v )[:_PROP_MAXLEN ]}
71
71
for k , v in model .get_params ().items ()]
72
72
)
73
73
@@ -217,12 +217,17 @@ def register_model(model, name, project, rep
10000
ository=None, input=None,
217
217
model .setdefault ('properties' , [])
218
218
219
219
# Define a custom property to capture each package version
220
+ # NOTE: some packages may not conform to the 'name==version' format
221
+ # expected here (e.g those installed with pip install -e). Such
222
+ # packages also generally contain characters that are not allowed
223
+ # in custom properties, so they are excluded here.
220
224
for p in packages :
221
- n , v = p .split ('==' )
222
- model ['properties' ].append ({
223
- 'name' : 'env_%s' % n ,
224
- 'value' : v
225
- })
225
+ if '==' in p :
226
+ n , v = p .split ('==' )
227
+ model ['properties' ].append ({
228
+ 'name' : 'env_%s' % n ,
229
+ 'value' : v
230
+ })
226
231
227
232
# Generate and upload a requirements.txt file
228
233
files .append ({'name' : 'requirements.txt' ,
@@ -264,7 +269,6 @@ def register_model(model, name, project, repository=None, input=None,
264
269
assert isinstance (model , dict ), "Expected an instance of %r. " \
265
270
" Received %r instead." % (dict (), model )
266
271
267
-
268
272
if create_project :
269
273
vars = model .get ('inputVariables' , [])[:]
270
274
vars += model .get ('outputVariables' , [])
0 commit comments