From d7d550352bd679604e1b22b9fb893171b1689a3f Mon Sep 17 00:00:00 2001 From: chaoz23 Date: Fri, 17 Jul 2026 22:19:47 -0700 Subject: [PATCH] MAINT replace deprecated scipy distance_matrix with cdist scipy 1.18 deprecates scipy.spatial.distance_matrix in favor of scipy.spatial.distance.cdist (removal scheduled for scipy 1.20), which currently raises a DeprecationWarning (and fails the SMOTEN tests that treat warnings as errors). Switch ValueDifferenceMetric to cdist with the Minkowski metric; the computed distances are identical. --- doc/whats_new/v0.15.rst | 7 +++++++ imblearn/metrics/pairwise.py | 5 +++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/doc/whats_new/v0.15.rst b/doc/whats_new/v0.15.rst index 7ef7284b8..162b22f69 100644 --- a/doc/whats_new/v0.15.rst +++ b/doc/whats_new/v0.15.rst @@ -17,5 +17,12 @@ Enhancements Compatibility ............. +- Replace the deprecated ``scipy.spatial.distance_matrix`` with + ``scipy.spatial.distance.cdist`` (Minkowski metric) in + :class:`~imblearn.metrics.pairwise.ValueDifferenceMetric`. This silences a + ``DeprecationWarning`` under SciPy 1.18 (the function is scheduled for + removal in SciPy 1.20); the computed distances are unchanged. + :pr:`1188` by :user:`chaoz23`. + Deprecations ............ diff --git a/imblearn/metrics/pairwise.py b/imblearn/metrics/pairwise.py index 701e7475a..2493120a1 100644 --- a/imblearn/metrics/pairwise.py +++ b/imblearn/metrics/pairwise.py @@ -6,7 +6,7 @@ import numbers import numpy as np -from scipy.spatial import distance_matrix +from scipy.spatial.distance import cdist from sklearn.base import BaseEstimator from sklearn.utils import check_consistent_length from sklearn.utils._param_validation import StrOptions @@ -227,7 +227,8 @@ def pairwise(self, X, Y=None): else: proba_feature_Y = proba_feature_X distance += ( - distance_matrix(proba_feature_X, proba_feature_Y, p=self.k) ** self.r + cdist(proba_feature_X, proba_feature_Y, metric="minkowski", p=self.k) + ** self.r ) return distance