8000 bugfix · Sivateja0689/python-sasctl@9196f66 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9196f66

Browse files
committed
bugfix
1 parent e2a0dd9 commit 9196f66

File tree

5 files changed

+35
-20
lines changed

5 files changed

+35
-20
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11

22
Unreleased
33
----------
4-
-
4+
**Bugfixes**
5+
- Added support for uint data types to the `register_model` task.
56

67
v1.4.4 (2019-10-31)
78
-------------------

src/sasctl/tasks.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@
2929

3030
logger = logging.getLogger(__name__)
3131

32+
# As of Viya 3.4 model registration fails if character fields are longer
33+
# than 1024 characters
34+
_DESC_MAXLEN = 1024
3235

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
3739

38-
# As of Viya 3.4 model registration fails if user-defined properties are
39-
# longer than 512 characters.
40-
PROP_MAXLEN = 512
4140

41+
def _sklearn_to_dict(model):
4242
# Convert Scikit-learn values to built-in Model Manager values
4343
mappings = {'LogisticRegression': 'Logistic regression',
4444
'LinearRegression': 'Linear regression',
@@ -59,15 +59,15 @@ def _sklearn_to_dict(model):
5959

6060
# Can tell if multi-class .multi_class
6161
result = dict(
62-
description=str(model)[:DESC_MAXLEN],
62+
description=str(model)[:_DESC_MAXLEN],
6363
algorithm=mappings.get(estimator.__name__, estimator.__name__),
6464
scoreCodeType='ds2MultiType',
6565
trainCodeType='Python',
6666
function=mappings.get(model._estimator_type, model._estimator_type),
6767
tool='Python %s.%s'
6868
% (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]}
7171
for k, v in model.get_params().items()]
7272
)
7373

@@ -217,12 +217,17 @@ def register_model(model, name, project, rep 10000 ository=None, input=None,
217217
model.setdefault('properties', [])
218218

219219
# 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.
220224
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+
})
226231

227232
# Generate and upload a requirements.txt file
228233
files.append({'name': 'requirements.txt',
@@ -264,7 +269,6 @@ def register_model(model, name, project, repository=None, input=None,
264269
assert isinstance(model, dict), "Expected an instance of %r. " \
265270
" Received %r instead." % (dict(), model)
266271

267-
268272
if create_project:
269273
vars = model.get('inputVariables', [])[:]
270274
vars += model.get('outputVariables', [])

src/sasctl/utils/pymas/ds2.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,12 @@ class DS2Variable(namedtuple('Ds2Variable', ['name', 'type', 'out'])):
304304
# Terminates search if full string matches
305305
('int64', 'integer'),
306306
('int32', 'integer'),
307-
('int', 'integer')
307+
('int', 'integer'),
308+
('uint8', 'integer'),
309+
('uint16', 'integer'),
310+
('uint32', 'integer'),
311+
('uint64', 'integer')
312+
308313
])
309314

310315
DS2_TYPE_TO_VIYA = OrderedDict([('double', 'decimal'),

src/sasctl/utils/pymas/python.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ def ds2_variables(input, output_vars=False):
6363
# Numpy array? No column names, but we can at least create dummy vars of the correct type
6464
types = OrderedDict([('var{}'.format(i),
6565
(input.dtype.name.replace('object', 'char'), False)) for i in range(1, len(input)+1)])
66-
# types = {'var{}'.format(i): (input.dtype.name.replace('object', 'char'), False) for i in range(1, len(input)+1)}
6766
elif six.callable(input):
6867
types = parse_type_hints(input)
6968
else:
70-
raise RuntimeError('Unable to determine input/ouput types using instance of type `%s`.' % type(input))
69+
raise RuntimeError("Unable to determine input/ouput types using "
70+
"instance of type '%s'." % type(input))
7171

7272
results = []
7373
for k, v in six.iteritems(types):

tests/unit/test_pymas.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,11 @@ def test_ds2_variables_dict_input():
208208
('b', str),
209209
('x', (float, True))]))
210210

211+
assert [DS2Variable('a', 'uint8', False),
212+
DS2Variable('b', 'uint16', False),
213+
DS2Variable('c', 'uint32', False),
214+
DS2Variable('d', 'uint64', False)] == ds2_variables(OrderedDict(a=int, b=int, c=int, d=int))
215+
211216

212217
def test_ds2_variables_func_input():
213218
target = [DS2Variable(name='x1', type='double', out=False),

0 commit comments

Comments
 (0)
0