fix: gridify() IndexError from numpy float // int staying float64 - #30
Merged
Conversation
BaseFeature2D.gridify() computed grid cell indices as f.p[0] // binwidth / f.p[1] // binheight. f.p is a numpy float array (feature point coordinates, shape (2,1)), and floor-dividing a numpy float array by a Python int still yields a float64 result -- so bins[iy, ix] always raised IndexError: arrays used as indices must be of integer (or boolean) type. This affected every call to gridify() regardless of whether nbins was passed as a tuple or scalar. Fix: extract the scalar value with .item() before floor-dividing, then cast to int explicitly. Added regression tests (gridify() had zero prior coverage) that fail with the exact reported IndexError against the unfixed code and pass against the fix -- verified both directions directly before committing.
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 0 |
| Duplication | 0 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
3 tasks
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.
Summary
BaseFeature2D.gridify()crashed withIndexError: arrays used as indices must be of integer (or boolean) typeon every call, regardless of whethernbinswas passed as a tuple or scalar.f.p[0] // binwidth/f.p[1] // binheight—f.pis a numpy float array (shape(2,1)), and floor-dividing a numpy float array by a Python int still yields afloat64result, not an int.bins[iy, ix]then rejects the float-typed index.int(f.p[0].item() // binwidth)— extract the scalar with.item()first, then cast.gridify()had zero test coverage before this. Added two regression tests (scalar and tuplenbins). Verified genuinely: reverted just the source fix (kept the test), confirmed both tests fail with the exact reportedIndexError, then restored the fix and confirmed they pass.main(confirmed viagit stash), so it's pre-existing, not something that fix introduced.Test plan