Skip to content

Commit 8d01acf

Browse files
authored
MAINT Clean up deprecations for 1.6: in AgglomerativeClustering (scikit-learn#29915)
1 parent a9ec347 commit 8d01acf

File tree

2 files changed

+3
-33
lines changed

2 files changed

+3
-33
lines changed

sklearn/cluster/_agglomerative.py

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -803,10 +803,6 @@ class AgglomerativeClustering(ClusterMixin, BaseEstimator):
803803
804804
.. versionadded:: 1.2
805805
806-
.. deprecated:: 1.4
807-
`metric=None` is deprecated in 1.4 and will be removed in 1.6.
808-
Let `metric` be the default value (i.e. `"euclidean"`) instead.
809-
810806
memory : str or object with the joblib.Memory interface, default=None
811807
Used to cache the output of the computation of the tree.
812808
By default, no caching is done. If a string is given, it is the
@@ -939,7 +935,6 @@ class AgglomerativeClustering(ClusterMixin, BaseEstimator):
939935
"metric": [
940936
StrOptions(set(_VALID_METRICS) | {"precomputed"}),
941937
callable,
942-
Hidden(None),
943938
],
944939
"memory": [str, HasMethods("cache"), None],
945940
"connectivity": ["array-like", "sparse matrix", callable, None],
@@ -1008,20 +1003,6 @@ def _fit(self, X):
10081003
"""
10091004
memory = check_memory(self.memory)
10101005

1011-
# TODO(1.6): remove in 1.6
1012-
if self.metric is None:
1013-
warnings.warn(
1014-
(
1015-
"`metric=None` is deprecated in version 1.4 and will be removed in "
1016-
"version 1.6. Let `metric` be the default value "
1017-
"(i.e. `'euclidean'`) instead."
1018-
),
1019-
FutureWarning,
1020-
)
1021-
self._metric = "euclidean"
1022-
else:
1023-
self._metric = self.metric
1024-
10251006
if not ((self.n_clusters is None) ^ (self.distance_threshold is None)):
10261007
raise ValueError(
10271008
"Exactly one of n_clusters and "
@@ -1034,9 +1015,9 @@ def _fit(self, X):
10341015
"compute_full_tree must be True if distance_threshold is set."
10351016
)
10361017

1037-
if self.linkage == "ward" and self._metric != "euclidean":
1018+
if self.linkage == "ward" and self.metric != "euclidean":
10381019
raise ValueError(
1039-
f"{self._metric} was provided as metric. Ward can only "
1020+
f"{self.metric} was provided as metric. Ward can only "
10401021
"work with euclidean distances."
10411022
)
10421023

@@ -1070,7 +1051,7 @@ def _fit(self, X):
10701051
kwargs = {}
10711052
if self.linkage != "ward":
10721053
kwargs["linkage"] = self.linkage
1073-
kwargs["affinity"] = self._metric
1054+
kwargs["affinity"] = self.metric
10741055

10751056
distance_threshold = self.distance_threshold
10761057

sklearn/cluster/tests/test_hierarchical.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -887,14 +887,3 @@ def test_precomputed_connectivity_metric_with_2_connected_components():
887887

888888
assert_array_equal(clusterer.labels_, clusterer_precomputed.labels_)
889889
assert_array_equal(clusterer.children_, clusterer_precomputed.children_)
890-
891-
892-
# TODO(1.6): remove in 1.6
893-
@pytest.mark.parametrize(
894-
"Agglomeration", [AgglomerativeClustering, FeatureAgglomeration]
895-
)
896-
def test_deprecation_warning_metric_None(Agglomeration):
897-
X = np.array([[1, 2], [1, 4], [1, 0], [4, 2], [4, 4], [4, 0]])
898-
warn_msg = "`metric=None` is deprecated in version 1.4 and will be removed"
899-
with pytest.warns(FutureWarning, match=warn_msg):
900-
Agglomeration(metric=None).fit(X)

0 commit comments

Comments
 (0)