Repository navigation
Closed as duplicate
Labels
Description
Describe the bug and give evidence about its user-facing impact
Hi I was running an automated test and ran into this issue.
Checked the changelog for Numpy as saw as of v2.4.0 that conversion of an array with ndim > 0 to a scalar is deprecated. The error below looks like this is linked to that deprecation.
/opt/hostedtoolcache/Python/3.11.14/x64/lib/python3.11/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:866: in fit
self.labels_, self.probabilities_ = tree_to_labels(
sklearn/cluster/_hdbscan/_tree.pyx:61: in sklearn.cluster._hdbscan._tree.tree_to_labels
???
sklearn/cluster/_hdbscan/_tree.pyx:75: in sklearn.cluster._hdbscan._tree.tree_to_labels
???
sklearn/cluster/_hdbscan/_tree.pyx:751: in sklearn.cluster._hdbscan._tree._get_clusters
???
sklearn/cluster/_hdbscan/_tree.pyx:626: in sklearn.cluster._hdbscan._tree.epsilon_search
???
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> ???
E TypeError: only 0-dimensional arrays can be converted to Python scalars
Not sure if this issue is applicable to other areas of the sklearn lib but hope it is not to big of an issue.
My env was using scikit-learn==1.8.0 and numpy==2.4.2
Steps/Code to Reproduce
import numpy as np
from sklearn.cluster import HDBSCAN
X = np.random.normal(0, 1, 1000)
X = np.atleast_2d(X).T
clust = HDBSCAN(cluster_selection_epsilon=np.std(X) / np.sqrt(2))
clust.fit(X)
Expected Results
No error is thrown
Actual Results
/opt/hostedtoolcache/Python/3.11.14/x64/lib/python3.11/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:866: in fit
self.labels_, self.probabilities_ = tree_to_labels(
sklearn/cluster/_hdbscan/_tree.pyx:61: in sklearn.cluster._hdbscan._tree.tree_to_labels
???
sklearn/cluster/_hdbscan/_tree.pyx:75: in sklearn.cluster._hdbscan._tree.tree_to_labels
???
sklearn/cluster/_hdbscan/_tree.pyx:751: in sklearn.cluster._hdbscan._tree._get_clusters
???
sklearn/cluster/_hdbscan/_tree.pyx:626: in sklearn.cluster._hdbscan._tree.epsilon_search
???
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> ???
E TypeError: only 0-dimensional arrays can be converted to Python scalars
Versions
scikit-learn==1.8.0
numpy==2.4.2Interest in fixing the bug
Not sure how to fix
Activity
deepith-18 commentedon Feb 22, 2026
Can i work on this issue.
NandiniDhanrale commentedon Feb 22, 2026
I’m also interested in taking a look, I’ll start by bisecting the offending line and share a minimal patch.
mohsinm-dev commentedon Feb 22, 2026
Root cause appears to be in
sklearn/cluster/_hdbscan/_tree.pyx(traverse_upwards): two boolean-indexed field lookups return 1D arrays that are assigned to Cython scalar-typed variables, which now raises with NumPy 2.4 (only 0-dimensional arrays can be converted to Python scalars).The proposed fix is explicit scalar extraction:
parent = cluster_tree[cluster_tree['child'] == leaf]['parent'][0]parent_eps = 1 / cluster_tree[cluster_tree['child'] == parent]['value'][0]I validated it locally:
I can open a PR after the
Needs Triagelabel is removed, including a non-regression test and changelog fragment.AlwaysTwilight commentedon Feb 22, 2026
AlwaysTwilight commentedon Feb 22, 2026
lesteve commentedon Feb 23, 2026
Seems like a duplicate of #33219.