Skip to content

Fix WeightedMinHash input mutation#317

Merged
ekzhu merged 2 commits into
ekzhu:masterfrom
dipeshbabu:fix-weighted-minhash-input-mutation
Apr 17, 2026
Merged

Fix WeightedMinHash input mutation#317
ekzhu merged 2 commits into
ekzhu:masterfrom
dipeshbabu:fix-weighted-minhash-input-mutation

Conversation

@dipeshbabu
Copy link
Copy Markdown
Contributor

Summary

Fixes a mutation bug in WeightedMinHashGenerator.minhash() where passing a np.float32 input array with zero values caused the caller-owned array to be modified in place.

The method replaces zero entries with NaN internally before taking logs. For existing float32 numpy arrays, the code reused the caller’s array directly, so zeros in the original input became NaN after calling minhash().

Fix

  • Copy float32 numpy inputs before applying the internal zero-to-NaN transformation.
  • Add a regression test to confirm minhash() does not mutate float32 input arrays.

Tests

python -m pytest -o addopts= test/test_weighted_minhash.py
python -m pytest -o addopts= test/test_minhash.py test/test_hyperloglog.py test/test_lshforest.py

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 17, 2026

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (master@c7c8df0). Learn more about missing BASE report.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff            @@
##             master     #317   +/-   ##
=========================================
  Coverage          ?   66.97%           
=========================================
  Files             ?       21           
  Lines             ?     2616           
  Branches          ?        0           
=========================================
  Hits              ?     1752           
  Misses            ?      864           
  Partials          ?        0           
Flag Coverage Δ
unittests 66.97% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request ensures that the input array v in the minhash method of WeightedMinHashGenerator is copied when it is already of type float32, preventing unintended mutation of the original input. A corresponding test case has been added to verify this behavior. I have no feedback to provide.

@ekzhu ekzhu merged commit 2d3655f into ekzhu:master Apr 17, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants