From e43e27630b1470883065a5a6715f8e926b347afe Mon Sep 17 00:00:00 2001 From: Joe Cainey Date: Wed, 12 Jun 2024 18:37:01 +0100 Subject: [PATCH 1/2] Fix typo in error message when attempting to cluster with more clusters than items --- sklearn/cluster/_agglomerative.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sklearn/cluster/_agglomerative.py b/sklearn/cluster/_agglomerative.py index d8cf1002dfcfe..bda505b3b562e 100644 --- a/sklearn/cluster/_agglomerative.py +++ b/sklearn/cluster/_agglomerative.py @@ -755,8 +755,7 @@ def _hc_cut(n_clusters, children, n_leaves): if n_clusters > n_leaves: raise ValueError( "Cannot extract more clusters than samples: " - "%s clusters where given for a tree with %s leaves." - % (n_clusters, n_leaves) + "%s clusters were given for a tree with %s leaves." % (n_clusters, n_leaves) ) # In this function, we store nodes as a heap to avoid recomputing # the max of the nodes: the first element is always the smallest From 8ee14068278a63e3282450e5647c3103b3615a47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Est=C3=A8ve?= Date: Fri, 14 Jun 2024 13:48:07 +0200 Subject: [PATCH 2/2] Update sklearn/cluster/_agglomerative.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jérémie du Boisberranger --- sklearn/cluster/_agglomerative.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sklearn/cluster/_agglomerative.py b/sklearn/cluster/_agglomerative.py index bda505b3b562e..55215d2a0312c 100644 --- a/sklearn/cluster/_agglomerative.py +++ b/sklearn/cluster/_agglomerative.py @@ -755,7 +755,7 @@ def _hc_cut(n_clusters, children, n_leaves): if n_clusters > n_leaves: raise ValueError( "Cannot extract more clusters than samples: " - "%s clusters were given for a tree with %s leaves." % (n_clusters, n_leaves) + f"{n_clusters} clusters were given for a tree with {n_leaves} leaves." ) # In this function, we store nodes as a heap to avoid recomputing # the max of the nodes: the first element is always the smallest