Skip to content

Commit a4ec570

Browse files
Merge pull request #2 from sassoftware/master
sync
2 parents ec358d5 + a6e1bd7 commit a4ec570

File tree

4 files changed

+16
-12
lines changed

4 files changed

+16
-12
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ Unreleased
33
----------
44
-
55

6+
v1.4.1 (2019-10-17)
7+
-------------------
8+
**Bugfixes**
9+
- Fixed an issue where string inputs to Python models were incorrectly handled by DS2.
10+
611
v1.4 (2019-10-15)
712
-----------------
813
**Changes**

src/sasctl/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Copyright © 2019, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
55
# SPDX-License-Identifier: Apache-2.0
66

7-
__version__ = '1.4'
7+
__version__ = '1.4.1'
88
__author__ = 'SAS'
99
__credits__ = ['Yi Jian Ching, Lucas De Paula, James Kochuba, Peter Tobac, '
1010
'Chris Toth, Jon Walker']

src/sasctl/utils/pymas/core.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,19 @@ def build_wrapper_function(func, variables, array_input, setup=None,
5959
func = func.__name__ if callable(func) else func
6060

6161
# HELPER: SAS to python char issue where SAS char have spaces and python string does not.
62-
# NOTE: we assume SAS char always need white space to be trimmed. This seems to match python model built so far
63-
pythonStringInput = ('',)
64-
for tmp1 in variables:
65-
if not tmp1.out:
66-
if tmp1.type == 'char':
67-
pythonStringInput = pythonStringInput + (" if " + tmp1.name + ": " + tmp1.name + " = " + tmp1.name + ".strip()",)
62+
# NOTE: we assume SAS char always need white space to be trimmed. This seems to match python model built so far
63+
string_input = ('', )
64+
for v in variables:
65+
if v.type == 'char' and not v.out:
66+
string_input += (" if {0}: {0} = {0}.strip()".format(v.name), )
6867

6968
# Statement to execute the function w/ provided parameters
7069
if array_input:
71-
middle = pythonStringInput +\
70+
middle = string_input +\
7271
(' inputarray = np.array([{}]).reshape((1, -1))'.format(','.join(args)),
73-
' column=[{}]'.format(','.join('"{0}"'.format(w) for w in args)),
72+
' column = [{}]'.format(','.join('"{0}"'.format(w) for w in args)),
7473
' import pandas as pd',
75-
' inputrun=pd.DataFrame(data=inputarray, columns=column)',
74+
' inputrun = pd.DataFrame(data=inputarray, columns=column)',
7675
' result = {}(inputrun)'.format(func))
7776
else:
7877
func_call = '{}({})'.format(func, ','.join(args))

tests/integration/test_pymas.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,9 @@ def test_from_pickle(train_data, pickle_file):
186186
rc = py.appendSrcLine(' import numpy as np');
187187
rc = py.appendSrcLine('');
188188
rc = py.appendSrcLine(' inputarray = np.array([SepalLength,SepalWidth,PetalLength,PetalWidth]).reshape((1, -1))');
189-
rc = py.appendSrcLine(' column=["SepalLength","SepalWidth","PetalLength","PetalWidth"]');
189+
rc = py.appendSrcLine(' column = ["SepalLength","SepalWidth","PetalLength","PetalWidth"]');
190190
rc = py.appendSrcLine(' import pandas as pd');
191-
rc = py.appendSrcLine(' inputrun=pd.DataFrame(data=inputarray, columns=column)');
191+
rc = py.appendSrcLine(' inputrun = pd.DataFrame(data=inputarray, columns=column)');
192192
rc = py.appendSrcLine(' result = obj.predict(inputrun)');
193193
rc = py.appendSrcLine(' if result.size == 1:');
194194
rc = py.appendSrcLine(' result = np.asscalar(result)');

0 commit comments

Comments
 (0)