Skip to content

Commit 2d0126c

Browse files
committed
Handle multiple score resources in model migration + black linting
1 parent f0f0797 commit 2d0126c

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/sasctl/pzmm/writeScoreCode.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def writeScoreCode(
2828
scoreCAS=True,
2929
isBinaryModel=False,
3030
binaryString=None,
31-
pickleType='pickle',
31+
pickleType="pickle",
3232
):
3333
"""
3434
Writes a Python score code file based on training data used to generate the model
@@ -102,7 +102,7 @@ def writeScoreCode(
102102
Sets whether data used for scoring needs to go through imputation for
103103
missing values before passed to the model. By default False.
104104
scoreCAS : boolean, optional
105-
Sets whether models registered to SAS Viya 3.5 should be able to be scored and
105+
Sets whether models registered to SAS Viya 3.5 should be able to be scored and
106106
validated through both CAS and SAS Micro Analytic Service. By default true. If
107107
set to false, then the model will only be able to be scored and validated through
108108
SAS Micro Analytic Service. By default True.

src/sasctl/utils/modelMigration.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ def convertMetadata(zPath, pythonScoreCode=None):
2626
2727
Returns
2828
-------
29-
scoreResource : string
30-
File name of the score resource file.
29+
scoreResource : list
30+
File name(s) of the score resource file.
3131
pythonScoreCode : string
3232
File name of the Python score code file.
3333
@@ -67,11 +67,14 @@ def convertMetadata(zPath, pythonScoreCode=None):
6767
+ " name of the Python score code file as an argument."
6868
)
6969
raise SyntaxError(message)
70+
scoreResource = []
7071
for i in range(len(metaData)):
7172
if metaData[i]["role"] == "score":
7273
metaData[i].update({"name": pythonScoreCode})
7374
if metaData[i]["role"] == "scoreResource":
74-
scoreResource = metaData[i]["name"]
75+
scoreResource.append(metaData[i]["name"])
76+
if metaData[i]["role"] == "python pickle":
77+
scoreResource.append(metaData[i]["name"])
7578
with open(Path(zPath) / "fileMetaData.json", "w") as jFile:
7679
json.dump(metaData, jFile, indent=4, skipkeys=True)
7780
print("fileMetaData.json has been modified and rewritten for SAS Viya 4")
@@ -89,8 +92,8 @@ def convertScoreCode(zPath, scoreResource, pythonScoreCode):
8992
----------
9093
zPath : string or Path object
9194
Location of files in the SAS Viya 3.5 model zip.
92-
scoreResource : string
93-
File name of the score resource file.
95+
scoreResource : list
96+
File name(s) of the score resource file.
9497
pythonScoreCode : string
9598
File name of the Python score code file.
9699
"""
@@ -103,7 +106,9 @@ def convertScoreCode(zPath, scoreResource, pythonScoreCode):
103106

104107
# Search for all directory paths in score code that contain the scoreResource
105108
oldString = re.findall(r"['\"]\/.*?\.[\w:]+['\"]", scoreCode)
106-
oldString = [s for s in oldString if scoreResource in s]
109+
parsedOldString = []
110+
for resource in scoreResource:
111+
parsedOldString = parsedOldString + [s for s in oldString if resource in s]
107112
# Remove duplicates, as .replace() checks for all instances
108113
oldString = list(set(oldString))
109114
# Replace Viya 3.5 style with Viya 4 style

0 commit comments

Comments
 (0)