Skip to content

FIX: HDBSCAN TypeError with cluster_selection_epsilon on tied distances - #33455

Closed
repeating wants to merge 2 commits into
scikit-learn:mainfrom
repeating:fix/hdbscan-epsilon-traverse-upwards
Closed

repeating wants to merge 2 commits into
scikit-learn:mainfrom
repeating:fix/hdbscan-epsilon-traverse-upwards

Conversation

@repeating

Copy link
Copy Markdown

closes #33219

the traverse_upwards function in _tree.pyx does boolean-indexed lookups on the condensed tree structured array:

parent = cluster_tree[cluster_tree['child'] == leaf]['parent']
parent_eps = 1 / cluster_tree[cluster_tree['child'] == parent]['value']

these always return shape-(1,) arrays, not scalars. numpy < 2.0 silently coerced shape-(1,) to scalar during cython typed assignment, but numpy 2.0 made this strict and raises TypeError: only 0-dimensional arrays can be converted to Python scalars.

the fix adds [0] to both lookups to explicitly extract the scalar. this is always safe since each child node has exactly one parent in the condensed tree.

added a non-regression test using the exact distance matrix from the issue.

AI usage disclosure

I used AI assistance for:

  • Code generation (e.g., when writing an implementation or fixing a bug)
  • Test/benchmark generation
  • Documentation (including examples)
  • Research and understanding

@github-actions github-actions Bot added module:cluster cython CI:Linter failure The linter CI is failing on this PR labels Mar 4, 2026
@github-actions github-actions Bot removed the CI:Linter failure The linter CI is failing on this PR label Mar 4, 2026

@virchan virchan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR, @repeating, and for helping improve scikit-learn.

I'm closing this PR per the Issues tagged "Needs Triage” section in the Contributing guide.

@repeating

Copy link
Copy Markdown
Author

thanks for the heads up, appreciate the pointer — i'll make sure to only pick up triaged issues going forward.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HDBSCAN fails when using cluster_selection_epsilon

2 participants