Skip to content

FIX Fix thread-safety of Mahalanobis distance computation - #34671

Draft
lesteve wants to merge 6 commits into
scikit-learn:mainfrom
lesteve:balltree-mahalanobis-thread-safety
Draft

lesteve wants to merge 6 commits into
scikit-learn:mainfrom
lesteve:balltree-mahalanobis-thread-safety

Conversation

@lesteve

@lesteve lesteve commented Aug 7, 2026 •

Copy link
Copy Markdown
Member

Reference Issues/PRs

Fixes #32753

What does this implement/fix? Explain your changes.

The dense case is reasonably simple this removes self.buffer which was shared and not thread-safe.

I haven't looked closely at the sparse change closely. Need to do this.

This also begs the question why do we even have our Mahalanobis distance implementation rather than using scipy for this? There may be a reason, and probably a bit of code archaeology will give us some hints.

AI usage disclosure

I used AI assistance for:

  • Code generation (e.g., when writing an implementation or fixing a bug)
  • Test/benchmark generation

Any other comments

Note that this is an issue for vanilla CPython, i.e. this is not related to free-threaded.

@github-actions github-actions Bot added the CI:Linter failure The linter CI is failing on this PR label Aug 12, 2026
@github-actions github-actions Bot removed the CI:Linter failure The linter CI is failing on this PR label Aug 17, 2026

This branch has not been deployed

No deployments
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.

LocalOutlierFactor with Mahalanobis distance returns different results based on n_jobs parameter

1 participant