Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preprocess code #203

Merged
merged 7 commits into from
Oct 28, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
black reformatting
  • Loading branch information
djm21 committed Oct 15, 2024
commit a7fdbfab04afba335c1a53a90efd83f0b75fb232
20 changes: 9 additions & 11 deletions src/sasctl/pzmm/write_score_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def score(var1, var2, var3, var4):

if preprocess_function:
self._add_preprocess_code(preprocess_function)

# SAS Viya 3.5 model
if model_id:
mas_code, cas_code = self._viya35_score_code_import(
Expand Down Expand Up @@ -2260,13 +2260,10 @@ def _viya35_score_code_import(
mr.update_model(model)
return mas_code, cas_code

def _add_preprocess_code(
self,
preprocess_function: Callable[DataFrame, DataFrame]
):
def _add_preprocess_code(self, preprocess_function: Callable[DataFrame, DataFrame]):
"""
Places the given preprocess function, which must both take a DataFrame as an argument
and return a DataFrame, into the score code. If the preprocess function does not
and return a DataFrame, into the score code. If the preprocess function does not
return anything, an error is thrown.

Parameters
Expand All @@ -2275,14 +2272,15 @@ def _add_preprocess_code(
The preprocess function to be added to the score code.
"""
import inspect

preprocess_code = inspect.getsource(preprocess_function)
if not "return" in preprocess_code:
raise ValueError(
"The given score code does not return a value. " +
"To allow for the score code to work correctly, please ensure the preprocessed " +
"data is returned."
"The given score code does not return a value. "
+ "To allow for the score code to work correctly, please ensure the preprocessed "
+ "data is returned."
)
if self.score_code[-1] == '\n':
if self.score_code[-1] == "\n":
self.score_code += preprocess_code
else:
self.score_code += '\n' + preprocess_code
self.score_code += "\n" + preprocess_code
Loading