Skip to content

Commit 5b7ad19

Browse files
committed
Fix improper row assignment for Lift charts as noted by #169
1 parent c8be42a commit 5b7ad19

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/sasctl/pzmm/write_json_files.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,7 @@ def calculate_model_statistics(
875875
json_dict[1]["data"][j].update(roc_dict[j])
876876

877877
lift_df = pd.DataFrame(conn.CASTable("Lift", caslib="Public").to_frame())
878-
lift_dict = cls.apply_dataframe_to_json(json_dict[2]["data"], i, lift_df)
878+
lift_dict = cls.apply_dataframe_to_json(json_dict[2]["data"], i, lift_df, 1)
879879
for j in range(len(lift_dict)):
880880
json_dict[2]["data"][j].update(lift_dict[j])
881881

@@ -1019,7 +1019,7 @@ def stat_dataset_to_dataframe(
10191019

10201020
@staticmethod
10211021
def apply_dataframe_to_json(
1022-
json_dict: dict, partition: int, stat_df: DataFrame
1022+
json_dict: dict, partition: int, stat_df: DataFrame, is_lift: bool = False
10231023
) -> dict:
10241024
"""
10251025
Map the values of the ROC or Lift charts from SAS CAS to the dictionary
@@ -1033,6 +1033,9 @@ def apply_dataframe_to_json(
10331033
Numerical representation of the data partition. Either 0, 1, or 2.
10341034
stat_df : pandas.DataFrame
10351035
ROC or Lift DataFrame generated from the SAS CAS percentile action set.
1036+
is_lift : bool
1037+
Specify whether to use logic for Lift or ROC row counting. Default value is
1038+
False.
10361039
10371040
Returns
10381041
-------
@@ -1042,7 +1045,10 @@ def apply_dataframe_to_json(
10421045
"""
10431046
for row_num in range(len(stat_df)):
10441047
row_dict = stat_df.iloc[row_num].replace(float("nan"), None).to_dict()
1045-
json_dict[row_num + partition * len(stat_df)]["dataMap"].update(row_dict)
1048+
if is_lift:
1049+
json_dict[(row_num + partition + 1) + partition * len(stat_df)]["dataMap"].update(row_dict)
1050+
else:
1051+
json_dict[row_num + (partition * len(stat_df))]["dataMap"].update(row_dict)
10461052
return json_dict
10471053

10481054
# noinspection PyCallingNonCallable, PyNestedDecorators

0 commit comments

Comments
 (0)