10000 API Remove `sklearn.metrics.manhattan_distances` option `sum_over_fea… · scikit-learn/scikit-learn@7cf938c · GitHub
[go: up one dir, main page]

Skip to content

Commit 7cf938c

Browse files
authored
API Remove sklearn.metrics.manhattan_distances option sum_over_features (#24630)
1 parent 6697de3 commit 7cf938c

File tree

3 files changed

+36
-7
lines changed

3 files changed

+36
-7
lines changed

doc/whats_new/v1.2.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,10 @@ Changelog
428428
(`average="micro"`) for the One-vs-Rest multiclass case (`multi_class="ovr"`).
429429
:pr:`24338` by :user:`Arturo Amor <ArturoAmorQ>`.
430430

431+
- |API| The parameter `sum_over_features` of :func:`metrics.pairwise.manhattan_distances` is deprecated
432+
and will be removed in 1.4.
433+
:pr:`24630` by :user:`Rushil Desai <rusdes>`.
434+
431435
:mod:`sklearn.model_selection`
432436
..............................
433437

sklearn/metrics/pairwise.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,7 @@ def haversine_distances(X, Y=None):
873873
return DistanceMetric.get_metric("haversine").pairwise(X, Y)
874874

875875

876-
def manhattan_distances(X, Y=None, *, sum_over_features=True):
876+
def manhattan_distances(X, Y=None, *, sum_over_features="deprecated"):
877877
"""Compute the L1 distances between the vectors in X and Y.
878878
879879
With sum_over_features equal to False it returns the componentwise
@@ -895,6 +895,10 @@ def manhattan_distances(X, Y=None, *, sum_over_features=True):
895895
else it returns the componentwise L1 pairwise-distances.
896896
Not supported for sparse matrix inputs.
897897
898+
.. deprecated:: 1.2
899+
``sum_over_features`` was deprecated in version 1.2 and will be removed in
900+
1.4.
901+
898902
Returns
899903
-------
900904
D : ndarray of shape (n_samples_X * n_samples_Y, n_features) or \
@@ -924,13 +928,17 @@ def manhattan_distances(X, Y=None, *, sum_over_features=True):
924928
[[1, 2], [0, 3]])
925929
array([[0., 2.],
926930
[4., 4.]])
927-
>>> import numpy as np
928-
>>> X = np.ones((1, 2))
929-
>>> y = np.full((2, 2), 2.)
930-
>>> manhattan_distances(X, y, sum_over_features=False)
931-
array([[1., 1.],
932-
[1., 1.]])
933931
"""
932+
# TODO(1.4): remove sum_over_features
933+
if sum_over_features != "deprecated":
934+
warnings.warn(
935+
"`sum_over_features` is deprecated in version 1.2 and will be"
936+
" removed in version 1.4.",
937+
FutureWarning,
938+
)
939+
else:
940+
sum_over_features = True
941+
934942
X, Y = check_pairwise_arrays(X, Y)
935943

936944
if issparse(X) or issparse(Y):

sklearn/metrics/tests/test_pairwise.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,23 @@ def test_pairwise_distances(global_dtype):
196196
pairwise_distances(X, Y, metric="blah")
197197

198198

199+
# TODO(1.4): Remove test when `sum_over_features` parameter is removed
200+
@pytest.mark.parametrize("sum_over_features", [True, False])
201+
def test_manhattan_distances_deprecated_sum_over_features(sum_over_features):
202+
# Check that future warning is raised when user
203+
# enters `sum_over_features` argument.
204+
X = [[1, 2], [3, 4]]
205+
Y = [[1, 2], [0, 3]]
206+
with pytest.warns(
207+
FutureWarning,
208+
match=(
209+
"`sum_over_features` is deprecated in version 1.2 and will be"
210+
" removed in version 1.4."
211+
),
212+
):
213+
manhattan_distances(X, Y, sum_over_features=sum_over_features)
214+
215+
199216
@pytest.mark.parametrize("metric", PAIRWISE_BOOLEAN_FUNCTIONS)
200217
def test_pairwise_boolean_distance(metric):
201218
# test that we convert to boolean arrays for boolean distances

0 commit comments

Comments
 (0)
0