Skip to content

Commit

Permalink
fix feature_bin_stats & rule.save
Browse files Browse the repository at this point in the history
  • Loading branch information
itlubber committed Sep 2, 2024
1 parent 12b8a05 commit 6b826b9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
14 changes: 13 additions & 1 deletion scorecardpipeline/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -838,8 +838,16 @@ def feature_bin_stats(data, feature, target="target", overdue=None, dpd=None, ru
if overdue and dpd is None:
raise ValueError("传入 overdue 参数时必须同时传入 dpd")

drop_empty = True if not empty_separate and data[feature].isnull().sum() <= 0 else False

if overdue is None:
return Combiner.feature_bin_stats(data, feature, target=target, rules=rules, method=method, desc=desc, combiner=combiner, ks=ks, max_n_bins=max_n_bins, min_bin_size=min_bin_size, max_bin_size=max_bin_size, greater_is_better=greater_is_better, empty_separate=empty_separate, return_cols=return_cols, return_rules=return_rules, verbose=verbose, **kwargs)
table, rule = Combiner.feature_bin_stats(data, feature, target=target, rules=rules, method=method, desc=desc, combiner=combiner, ks=ks, max_n_bins=max_n_bins, min_bin_size=min_bin_size, max_bin_size=max_bin_size, greater_is_better=greater_is_better, empty_separate=empty_separate, return_cols=return_cols, return_rules=True, verbose=verbose, **kwargs)

if drop_empty:
table = table.iloc[:-1]
rule = rule[:-1]

return table, rule if return_rules else table

if not isinstance(overdue, list):
overdue = [overdue]
Expand Down Expand Up @@ -879,6 +887,10 @@ def feature_bin_stats(data, feature, target="target", overdue=None, dpd=None, ru

table = table.merge(_table, on=[("分箱详情", c) for c in merge_columns])

if drop_empty:
table = table.iloc[:-1]
rule = rule[:-1]

if return_cols is not None:
if not isinstance(return_cols, list):
return_cols = [return_cols]
Expand Down
5 changes: 3 additions & 2 deletions scorecardpipeline/rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ def save(report, excel_writer, sheet_name=None, merge_column=None, percent_cols=

if percent_cols:
percent_cols = [c for c in report.columns if (isinstance(c, tuple) and c[-1] in percent_cols) or (not isinstance(c, tuple) and c in percent_cols)]

if condition_cols:
condition_cols = [c for c in report.columns if (isinstance(c, tuple) and c[-1] in condition_cols) or (not isinstance(c, tuple) and c in condition_cols)]

Expand All @@ -425,4 +425,5 @@ def save(report, excel_writer, sheet_name=None, merge_column=None, percent_cols=
if color_cols:
color_cols = [c for c in report.columns if (isinstance(c, tuple) and c[-1] in color_cols) or (not isinstance(c, tuple) and c in color_cols)]

dataframe2excel(report, excel_writer, sheet_name=sheet_name, merge_column=merge_column, percent_cols=percent_cols, condition_cols=condition_cols, custom_cols=custom_cols, custom_format=custom_format, color_cols=color_cols, start_col=start_col, start_row=start_row, **kwargs)
end_row, end_col = dataframe2excel(report, excel_writer, sheet_name=sheet_name, merge_column=merge_column, percent_cols=percent_cols, condition_cols=condition_cols, custom_cols=custom_cols, custom_format=custom_format, color_cols=color_cols, start_col=start_col, start_row=start_row, **kwargs)
return end_row, end_col

0 comments on commit 6b826b9

Please sign in to comment.