Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9f9ad18

Browse files
pravarmahajanamueller
authored andcommitted
[MRG+1] Deprecating the use of size_threshold parameter in manhattan_distances (#9295)
* deprecating size_threshold in manhattan_distances * fixing a minor pep8 error * version number for deprecation
1 parent 0759033 commit 9f9ad18

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

sklearn/metrics/pairwise.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import itertools
1313
from functools import partial
14+
import warnings
1415

1516
import numpy as np
1617
from scipy.spatial import distance
@@ -467,7 +468,7 @@ def pairwise_distances_argmin(X, Y, axis=1, metric="euclidean",
467468

468469

469470
def manhattan_distances(X, Y=None, sum_over_features=True,
470-
size_threshold=5e8):
471+
size_threshold=None):
471472
""" Compute the L1 distances between the vectors in X and Y.
472473
473474
With sum_over_features equal to False it returns the componentwise
@@ -520,6 +521,10 @@ def manhattan_distances(X, Y=None, sum_over_features=True,
520521
array([[ 1., 1.],
521522
[ 1., 1.]]...)
522523
"""
524+
if size_threshold is not None:
525+
warnings.warn('Use of the "size_threshold" is deprecated '
526+
'in 0.19 and it will be removed version '
527+
'0.21 of scikit-learn', DeprecationWarning)
523528
X, Y = check_pairwise_arrays(X, Y)
524529

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

sklearn/metrics/tests/test_pairwise.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from sklearn.utils.testing import assert_raises
1313
from sklearn.utils.testing import assert_raises_regexp
1414
from sklearn.utils.testing import assert_true
15+
from sklearn.utils.testing import assert_warns
1516
from sklearn.utils.testing import ignore_warnings
1617

1718
from sklearn.externals.six import iteritems
@@ -74,10 +75,10 @@ def test_pairwise_distances():
7475
assert_equal(S.shape[0], X.shape[0])
7576
assert_equal(S.shape[1], Y.shape[0])
7677
assert_array_almost_equal(S, S2)
77-
# Low-level function for manhattan can divide in blocks to avoid
78-
# using too much memory during the broadcasting
79-
S3 = manhattan_distances(X, Y, size_threshold=10)
80-
assert_array_almost_equal(S, S3)
78+
# Using size_threshold argument should raise
79+
# a deprecation warning
80+
assert_warns(DeprecationWarning,
81+
manhattan_distances, X, Y, size_threshold=10)
8182
# Test cosine as a string metric versus cosine callable
8283
# The string "cosine" uses sklearn.metric,
8384
# while the function cosine is scipy.spatial

0 commit comments

Comments
 (0)