sassoftware / python-sasctl

Python package and CLI for user-friendly integration with SAS Viya
https://sassoftware.github.io/python-sasctl
Apache License 2.0
45 stars 40 forks source link

Registering an Astore model with data of type 'Varchar' error when creating project (force = True) #153

Closed pinduzera closed 1 year ago

pinduzera commented 1 year ago

Registering an Astore model with data of type 'Varchar' error when creating project and registering model at the same mode (force = True). If the project already exists you can bypass the check, leading to a proper registration (or force = False).

Sample code:

result = conn.astore.describe(rstore= dict(name = "gb_astore", caslib= "Public" ), epcode=False)
var_list = [print(v) for v in result.InputVariables.itertuples()]

Output:

Pandas(Index=0, Name='CLAGE', Length=8.0, Role='Input', Type='Interval', RawType='Num', FormatName='')
Pandas(Index=1, Name='CLNO', Length=8.0, Role='Input', Type='Interval', RawType='Num', FormatName='')
Pandas(Index=2, Name='DEBTINC', Length=8.0, Role='Input', Type='Interval', RawType='Num', FormatName='')
Pandas(Index=3, Name='DELINQ', Length=8.0, Role='Input', Type='Interval', RawType='Num', FormatName='')
Pandas(Index=4, Name='DEROG', Length=8.0, Role='Input', Type='Interval', RawType='Num', FormatName='')
Pandas(Index=5, Name='LOAN', Length=8.0, Role='Input', Type='Interval', RawType='Num', FormatName='')
Pandas(Index=6, Name='MORTDUE', Length=8.0, Role='Input', Type='Interval', RawType='Num', FormatName='')
Pandas(Index=7, Name='NINQ', Length=8.0, Role='Input', Type='Interval', RawType='Num', FormatName='')
Pandas(Index=8, Name='VALUE', Length=8.0, Role='Input', Type='Interval', RawType='Num', FormatName='')
Pandas(Index=9, Name='YOJ', Length=8.0, Role='Input', Type='Interval', RawType='Num', FormatName='')
Pandas(Index=10, Name='JOB', Length=7.0, Role='Input', Type='Classification', RawType='Varchar', FormatName='')
Pandas(Index=11, Name='REASON', Length=7.0, Role='Input', Type='Classification', RawType='Varchar', FormatName='')
astore = conn.CASTable('gb_astore', caslib = "public")
model = register_model(astore, 'gb_swat', 'WebinarBrHmeq', force = True)

Error:

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
Cell In[120], line 2
      1 astore = conn.CASTable('gb_astore', caslib = "public")
----> 2 model = register_model(astore, 'gb_swat', 'WebinarBrHmeq2', force = True) #force = True to create the project

File /opt/conda/lib/python3.10/site-packages/sasctl/tasks.py:343, in register_model(model, name, project, repository, input, version, files, force, record_packages)
    340 model_props = utils.astore._get_model_properties(result)
    342 # Format input & output variable info as lists of dicts
--> 343 input_vars = [
    344     utils.astore.get_variable_properties(v)
    345     for v in result.InputVariables.itertuples()
    346 ]
    347 output_vars = [
    348     utils.astore.get_variable_properties(v)
    349     for v in result.OutputVariables.itertuples()
    350 ]
    352 # Set the variable 'role' if it wasn't included (not all astores specify)

File /opt/conda/lib/python3.10/site-packages/sasctl/tasks.py:344, in <listcomp>(.0)
    340 model_props = utils.astore._get_model_properties(result)
    342 # Format input & output variable info as lists of dicts
    343 input_vars = [
--> 344     utils.astore.get_variable_properties(v)
    345     for v in result.InputVariables.itertuples()
    346 ]
    347 output_vars = [
    348     utils.astore.get_variable_properties(v)
    349     for v in result.OutputVariables.itertuples()
    350 ]
    352 # Set the variable 'role' if it wasn't included (not all astores specify)

File /opt/conda/lib/python3.10/site-packages/sasctl/utils/astore.py:316, in get_variable_properties(var)
    314 # Input variable table has Type & RawType columns, but RawType aligns with Type column from Output variable table.
    315 if hasattr(var, "RawType"):
--> 316     meta["type"] = type_mapping[var.RawType.strip().lower()]
    317 else:
    318     meta["type"] = type_mapping[var.Type.strip().lower()]

KeyError: 'varchar'