Skip to content

Conversion of an array with ndim > 0 to a scalar deprecated #33355

Closed as duplicate

Description

@KulikDM

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.2

Interest in fixing the bug

Not sure how to fix

Activity

  1. added
    Needs Triage
    on Feb 22, 2026
  2. deepith-18 commented on Feb 22, 2026

    @deepith-18

    Can i work on this issue.

  3. NandiniDhanrale commented on Feb 22, 2026

    @NandiniDhanrale

    I’m also interested in taking a look, I’ll start by bisecting the offending line and share a minimal patch.

  4. mohsinm-dev commented on Feb 22, 2026

    @mohsinm-dev

    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:

    • Reproducer fails on unpatched code, and I tested it out.

    I can open a PR after the Needs Triage label is removed, including a non-regression test and changelog fragment.

  5. AlwaysTwilight commented on Feb 22, 2026

    @AlwaysTwilight
  6. AlwaysTwilight commented on Feb 22, 2026

    @AlwaysTwilight
  7. lesteve commented on Feb 23, 2026

    @lesteve
    Member

    Seems like a duplicate of #33219.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugNeeds Triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions