FIX: avoid EfficiencyWarning in OPTICS with metric='precomputed' - #34692
Merged
Conversation
DeaMariaLeon
commented
Aug 11, 2026
| # own neighbor | ||
| X.setdiag(X.diagonal()) | ||
| # Sorting could be undone by .setdiag(), make sure it's sorted | ||
| X = sort_graph_by_row_values(X, warn_when_not_sorted=False) |
Member
Author
There was a problem hiding this comment.
Note: The fix removes the EfficiencyWarning for every sparse precomputed input to OPTICS.fit. A user who passes an unsorted graph doesn't get a warning either.
This matches #34399 behaviour.
Member
Author
Member
Author
|
Friendly ping @cakedev0 in case this was forgotten |
Member
Author
|
Thank you! |
virchan
approved these changes
Sep 4, 2026
virchan
left a comment
Member
There was a problem hiding this comment.
LGTM! Thank you everyone for your time!
Member
Author
|
Thank you @virchan! |
cboseak
pushed a commit
to cboseak/scikit-learn
that referenced
this pull request
Sep 4, 2026
prady0t
pushed a commit
to prady0t/scikit-learn
that referenced
this pull request
Sep 6, 2026
jeremiedbb
pushed a commit
to jeremiedbb/scikit-learn
that referenced
this pull request
Sep 8, 2026
jeremiedbb
pushed a commit
to jeremiedbb/scikit-learn
that referenced
this pull request
Sep 8, 2026
jeremiedbb
pushed a commit
to jeremiedbb/scikit-learn
that referenced
this pull request
Sep 8, 2026
jeremiedbb
pushed a commit
to jeremiedbb/scikit-learn
that referenced
this pull request
Sep 9, 2026
jeremiedbb
pushed a commit
to jeremiedbb/scikit-learn
that referenced
this pull request
Sep 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reference Issues/PRs
Fixes #34647
What does this implement/fix? Explain your changes.
The issue and fix are the same as #34399:
OPTICSneeds each point to count as its own neighbour. So, for sparse input, the diagonal has to be made explicit.scikit-learn uses scipy's
setdiagto insert the point which un-sorts the sparse matrix that had already been sorted and emits a warning. To remove the warning (because points are not sorted), we need to callsort_graph_by_row_valuesafter the call tosetdiag.Note: The fix removes the
EfficiencyWarningfor every sparse precomputed input to OPTICS.fit. A user who passes an unsorted graph gets no warning either.This is matching #34399 behaviour.
AI usage disclosure
I used AI assistance for:
Any other comments?