diff --git a/python/dalex/NEWS.md b/python/dalex/NEWS.md index 8f714acda..00fa46ca5 100644 --- a/python/dalex/NEWS.md +++ b/python/dalex/NEWS.md @@ -2,6 +2,7 @@ ### development +* replaced instances of x.ptp() (with np.ptp(x)) and np.Inf (with np.inf) to make dx compatible with Numpy>=2.0.0 * added a way to pass `sample_weight` to loss functions in `model_parts()` (variable importance) using `weights` from `dx.Explainer` ([#563](https://github.com/ModelOriented/DALEX/issues/563)) * fixed the visualization of `shap_wrapper` for `shap==0.45.0` diff --git a/python/dalex/dalex/aspect/_model_aspect_importance/object.py b/python/dalex/dalex/aspect/_model_aspect_importance/object.py index e039427a4..29afeb00c 100644 --- a/python/dalex/dalex/aspect/_model_aspect_importance/object.py +++ b/python/dalex/dalex/aspect/_model_aspect_importance/object.py @@ -246,7 +246,7 @@ def plot( dl = _result_df.loc[ _result_df.aspect_name != "_baseline_", "dropout_loss" ].to_numpy() - min_max_margin = dl.ptp() * 0.15 + min_max_margin = np.ptp(dl) * 0.15 min_max = [dl.min() - min_max_margin, dl.max() + min_max_margin] # take out full model diff --git a/python/dalex/dalex/aspect/_model_triplot/object.py b/python/dalex/dalex/aspect/_model_triplot/object.py index b1f901e20..9797807ad 100644 --- a/python/dalex/dalex/aspect/_model_triplot/object.py +++ b/python/dalex/dalex/aspect/_model_triplot/object.py @@ -231,7 +231,7 @@ def plot( fig.data[0]["y"] = y_vals ## triplot - min_x_imp, max_x_imp = np.Inf, -np.Inf + min_x_imp, max_x_imp = np.inf, -np.inf for data in hierarchical_importance_dendrogram_plot["data"][::-1]: data["xaxis"] = "x2" data["hoverinfo"] = "text" @@ -241,7 +241,7 @@ def plot( max_x_imp = np.max([max_x_imp, np.max(data["x"])]) min_max_margin_imp = (max_x_imp - min_x_imp) * 0.15 - min_x_clust, max_x_clust = np.Inf, -np.Inf + min_x_clust, max_x_clust = np.inf, -np.inf for data in hierarchical_clustering_dendrogram_plot["data"]: data["xaxis"] = "x3" data["hoverinfo"] = "text" diff --git a/python/dalex/dalex/aspect/_model_triplot/plot.py b/python/dalex/dalex/aspect/_model_triplot/plot.py index 310f85303..eeee72997 100644 --- a/python/dalex/dalex/aspect/_model_triplot/plot.py +++ b/python/dalex/dalex/aspect/_model_triplot/plot.py @@ -148,8 +148,8 @@ def plot_single_aspects_importance( } ) - temp_min_max = [np.Inf, -np.Inf] - min_max_margin = _result.dropout_loss.values.ptp() * 0.15 + temp_min_max = [np.inf, -np.inf] + min_max_margin = np.ptp(_result.dropout_loss.values) * 0.15 temp_min_max[0] = np.min( [temp_min_max[0], baseline - min_max_margin] ) diff --git a/python/dalex/dalex/aspect/_predict_aspect_importance/object.py b/python/dalex/dalex/aspect/_predict_aspect_importance/object.py index a6756af19..68f7668d8 100644 --- a/python/dalex/dalex/aspect/_predict_aspect_importance/object.py +++ b/python/dalex/dalex/aspect/_predict_aspect_importance/object.py @@ -306,7 +306,7 @@ def plot( vcolors = _theme.get_aspect_importance_colors() if min_max is None: - temp_min_max = [np.Inf, -np.Inf] + temp_min_max = [np.inf, -np.inf] else: temp_min_max = min_max @@ -404,7 +404,7 @@ def plot( if min_max is None: cum = _result.importance.values + baseline - min_max_margin = cum.ptp() * 0.15 + min_max_margin = np.ptp(cum) * 0.15 temp_min_max[0] = np.min( [ temp_min_max[0], diff --git a/python/dalex/dalex/aspect/_predict_triplot/object.py b/python/dalex/dalex/aspect/_predict_triplot/object.py index 12f9fcf23..20d2ed2b0 100644 --- a/python/dalex/dalex/aspect/_predict_triplot/object.py +++ b/python/dalex/dalex/aspect/_predict_triplot/object.py @@ -284,7 +284,7 @@ def plot( line={"color": "#371ea3", "width": 1.5, "dash": "dot"}, ) - min_x_imp, max_x_imp = np.Inf, -np.Inf + min_x_imp, max_x_imp = np.inf, -np.inf for data in hierarchical_importance_dendrogram_plot["data"][::-1]: data["xaxis"] = "x2" data["hoverinfo"] = "text" @@ -294,7 +294,7 @@ def plot( max_x_imp = np.max([max_x_imp, np.max(data["x"])]) min_max_margin_imp = (max_x_imp - min_x_imp) * 0.15 - min_x_clust, max_x_clust = np.Inf, -np.Inf + min_x_clust, max_x_clust = np.inf, -np.inf for data in hierarchical_clustering_dendrogram_plot["data"]: data["xaxis"] = "x3" data["hoverinfo"] = "text" diff --git a/python/dalex/dalex/aspect/_predict_triplot/plot.py b/python/dalex/dalex/aspect/_predict_triplot/plot.py index b3028c6db..d5af045dd 100644 --- a/python/dalex/dalex/aspect/_predict_triplot/plot.py +++ b/python/dalex/dalex/aspect/_predict_triplot/plot.py @@ -239,8 +239,8 @@ def plot_single_aspects_importance( } ) - temp_min_max = [np.Inf, -np.Inf] - min_max_margin = _result.importance.values.ptp() * 0.15 + temp_min_max = [np.inf, -np.inf] + min_max_margin = np.ptp(_result.importance.values) * 0.15 temp_min_max[0] = np.min( [temp_min_max[0], _result.importance.values.min() - min_max_margin] ) diff --git a/python/dalex/dalex/model_explanations/_aggregated_profiles/object.py b/python/dalex/dalex/model_explanations/_aggregated_profiles/object.py index cdd37cf0e..faf7ddea6 100644 --- a/python/dalex/dalex/model_explanations/_aggregated_profiles/object.py +++ b/python/dalex/dalex/model_explanations/_aggregated_profiles/object.py @@ -242,7 +242,7 @@ def plot(self, # calculate y axis range to allow for fixedrange True dl = _result_df['_yhat_'].to_numpy() - min_max_margin = dl.ptp() * 0.10 + min_max_margin = np.ptp(dl) * 0.10 min_max = [dl.min() - min_max_margin, dl.max() + min_max_margin] is_x_numeric = False if geom == 'bars' else pd.api.types.is_numeric_dtype(_result_df['_x_']) diff --git a/python/dalex/dalex/model_explanations/_variable_importance/object.py b/python/dalex/dalex/model_explanations/_variable_importance/object.py index 70271142a..7e5cc078c 100644 --- a/python/dalex/dalex/model_explanations/_variable_importance/object.py +++ b/python/dalex/dalex/model_explanations/_variable_importance/object.py @@ -198,7 +198,7 @@ def plot(self, _global_checks.global_raise_objects_class(objects, self.__class__) dl = _result_df.loc[_result_df.variable != '_baseline_', 'dropout_loss'].to_numpy() - min_max_margin = dl.ptp() * 0.15 + min_max_margin = np.ptp(dl) * 0.15 min_max = [dl.min() - min_max_margin, dl.max() + min_max_margin] # take out full model diff --git a/python/dalex/dalex/predict_explanations/_break_down/object.py b/python/dalex/dalex/predict_explanations/_break_down/object.py index 79320ba0c..a3e9e407e 100644 --- a/python/dalex/dalex/predict_explanations/_break_down/object.py +++ b/python/dalex/dalex/predict_explanations/_break_down/object.py @@ -199,7 +199,7 @@ def plot(self, vcolors = _theme.get_break_down_colors() if min_max is None: - temp_min_max = [np.Inf, -np.Inf] + temp_min_max = [np.inf, -np.inf] else: temp_min_max = min_max @@ -256,7 +256,7 @@ def plot(self, if min_max is None: cum = df.cumulative.values - min_max_margin = cum.ptp() * 0.15 + min_max_margin = np.ptp(cum) * 0.15 temp_min_max[0] = np.min([temp_min_max[0], cum.min() - min_max_margin]) temp_min_max[1] = np.max([temp_min_max[1], cum.max() + min_max_margin]) diff --git a/python/dalex/dalex/predict_explanations/_ceteris_paribus/object.py b/python/dalex/dalex/predict_explanations/_ceteris_paribus/object.py index 89088dad7..a550e6325 100644 --- a/python/dalex/dalex/predict_explanations/_ceteris_paribus/object.py +++ b/python/dalex/dalex/predict_explanations/_ceteris_paribus/object.py @@ -262,7 +262,7 @@ def plot(self, # calculate y axis range to allow for fixedrange True dl = _result_df['_yhat_'].to_numpy() - min_max_margin = dl.ptp() * 0.10 + min_max_margin = np.ptp(dl) * 0.10 min_max = [dl.min() - min_max_margin, dl.max() + min_max_margin] # create _x_ diff --git a/python/dalex/dalex/predict_explanations/_shap/object.py b/python/dalex/dalex/predict_explanations/_shap/object.py index 920ea5bed..b8d4b6c90 100644 --- a/python/dalex/dalex/predict_explanations/_shap/object.py +++ b/python/dalex/dalex/predict_explanations/_shap/object.py @@ -205,7 +205,7 @@ def plot(self, vcolors = _theme.get_break_down_colors() if min_max is None: - temp_min_max = [np.Inf, -np.Inf] + temp_min_max = [np.inf, -np.inf] else: temp_min_max = min_max @@ -263,7 +263,7 @@ def plot(self, if min_max is None: cum = df.contribution.values + prediction_baseline - min_max_margin = cum.ptp() * 0.15 + min_max_margin = np.ptp(cum) * 0.15 temp_min_max[0] = np.min([temp_min_max[0], cum.min() - min_max_margin]) temp_min_max[1] = np.max([temp_min_max[1], cum.max() + min_max_margin])