fix: IndexError in get_topk_rois when indexing dict_keys with numpy#30
Conversation
|
Hi @Shubham0209! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
What's the bug?
When calling
get_topk_roiswith the defaulthemi="both"(or any value other than"both_separate"), the function crashes with:Root cause
The
elsebranch assignslabelsfrom a raw.keys()call:dict.keys()returns a view object, not a sequence. When passed tonp.array(), numpy wraps the entire object into a 0-dimensional array instead of a 1D string array. Fancy-indexing that 0-d array withtop_kthen raises theIndexError.Interestingly, the
both_separatebranch right above it already handles this correctly by constructing a plain Python list — theelsebranch was just missing the same treatment.Fix
One character change — wrap
.keys()inlist():This gives numpy a proper 1D sequence it can convert to a string array and fancy-index correctly.
Testing
Verified on a real brain encoding run with both text and video stimuli using the default
hemi="both".get_topk_roisnow returns the correct top-k parcel names without error.