Skip to content

Conversation

@AAAZZZR
Copy link

@AAAZZZR AAAZZZR commented Jan 12, 2026

Reference Issues/PRs

Fixes #33034

What does this implement/fix? Explain your changes.

When using KNeighborsClassifier with algorithm="brute" and p=1 (Manhattan distance), the code path utilizes ArgKminClassMode. Previously, self.classes_ (which can contain strings) was passed directly to the unique_Y_labels argument of the Cython method, causing a ValueError when it attempted to interpret strings as integers.

I have updated the call to pass np.arange(len(self.classes_), dtype=np.intp) instead, which provides the correct integer indices expected by the underlying Cython implementation.

Any other comments?

Added a regression test case in sklearn/neighbors/tests/test_neighbors.py.

@github-actions github-actions bot added module:neighbors CI:Linter failure The linter CI is failing on this PR labels Jan 12, 2026
@github-actions github-actions bot removed the CI:Linter failure The linter CI is failing on this PR label Jan 12, 2026
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.

KNeighborsClassifier fails on non-numeric labels with ValueError on certain parameters combination

1 participant