Skip to content

Commit

Permalink
Merge pull request #551 from guillaume-vignal/feature/change_apply_map
Browse files Browse the repository at this point in the history
replace apply_map by map for pandas>=2.1.0
  • Loading branch information
guillaume-vignal authored May 6, 2024
2 parents a71e48c + 3458024 commit 00cd8b7
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion requirements.dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dash-html-components==2.0.0
dash-renderer==1.8.3
dash-table==5.0.0
lightgbm==2.3.1
pandas>1.0.2
pandas>=2.1.0
plotly==5.6.0
shap>=0.38.1,<0.45.0
Sphinx==4.5.0
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"plotly>=5.0.0",
"matplotlib>=3.2.0",
"numpy>1.18.0",
"pandas>1.0.2",
"pandas>=2.1.0",
"shap>=0.38.1,<0.45.0",
"Flask<2.3.0",
"dash>=2.3.1",
Expand Down
6 changes: 3 additions & 3 deletions shapash/explainer/smart_plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1297,13 +1297,13 @@ def contribution_plot(
y_pred = self.explainer.y_pred.loc[list_ind]
# Add labels if exist
if self.explainer._case == "classification" and self.explainer.label_dict is not None:
y_pred = y_pred.applymap(lambda x: self.explainer.label_dict[x])
y_pred = y_pred.map(lambda x: self.explainer.label_dict[x])
col_value = self.explainer.label_dict[col_value]
# round predict
elif self.explainer._case == "regression":
if self.round_digit is None:
self.tuning_round_digit()
y_pred = y_pred.applymap(lambda x: round(x, self.round_digit))
y_pred = y_pred.map(lambda x: round(x, self.round_digit))
else:
y_pred = None

Expand Down Expand Up @@ -3346,7 +3346,7 @@ def _prediction_regression_plot(
# round predict
if self.round_digit is None:
self.tuning_round_digit()
y_pred = y_pred.applymap(lambda x: round(x, self.round_digit))
y_pred = y_pred.map(lambda x: round(x, self.round_digit))

hv_text = [
f"Id: {x}<br />True Values: {y:,.2f}<br />Predicted Values: {z:,.2f}<br />Prediction Error: {w:,.2f}"
Expand Down
2 changes: 1 addition & 1 deletion shapash/manipulation/select_lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def keep_right_contributions(y_pred, contributions, _case, _classes, label_dict,
dtype=object,
)
if label_dict is not None:
y_pred = y_pred.applymap(lambda x: label_dict[x])
y_pred = y_pred.map(lambda x: label_dict[x])
if proba_values is not None:
y_proba = pd.DataFrame(
[proba[ind] for ind, proba in zip(indexclas, proba_values.values)],
Expand Down
2 changes: 1 addition & 1 deletion shapash/manipulation/summarize.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def summarize(s_contrib, var_dict, x_sorted, mask, columns_dict, features_dict):
Result of the summarize step
"""
contrib_sum = summarize_el(s_contrib, mask, "contribution_")
var_dict_sum = summarize_el(var_dict, mask, "feature_").applymap(
var_dict_sum = summarize_el(var_dict, mask, "feature_").map(
lambda x: features_dict[columns_dict[x]] if not np.isnan(x) else x
)
x_sorted_sum = summarize_el(x_sorted, mask, "value_")
Expand Down
4 changes: 2 additions & 2 deletions shapash/webapp/smart_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ def __init__(self, explainer, settings: dict = None):
self.label = self.explainer.check_label_name(len(self.explainer._classes) - 1, "num")[1]
self.selected_feature = self.explainer.features_imp[-1].idxmax()
self.max_threshold = int(
max([x.applymap(lambda x: round_to_k(x, k=1)).max().max() for x in self.explainer.contributions])
max([x.map(lambda x: round_to_k(x, k=1)).max().max() for x in self.explainer.contributions])
)
else:
self.label = None
self.selected_feature = self.explainer.features_imp.idxmax()
self.max_threshold = int(self.explainer.contributions.applymap(lambda x: round_to_k(x, k=1)).max().max())
self.max_threshold = int(self.explainer.contributions.map(lambda x: round_to_k(x, k=1)).max().max())
self.list_index = []
self.subset = None
self.last_click_data = None
Expand Down

0 comments on commit 00cd8b7

Please sign in to comment.