Skip to content

fix mutating the input in snap_to_scalp_voxels#160

Merged
emiddell merged 1 commit into
devfrom
annoying-bug-fix
May 6, 2026
Merged

fix mutating the input in snap_to_scalp_voxels#160
emiddell merged 1 commit into
devfrom
annoying-bug-fix

Conversation

@harmening
Copy link
Copy Markdown
Contributor

This was a super annoying bug - it took me a bit to identify its cause:

The problem
snap_to_scalp_voxels takes a DataArray of optode positions (points) and figures out the nearest scalp-voxel coordinate for each. To return the snapped result, it did, but:

  points.values = snapped    # overwrite the caller's array in place !!!
  return points              # then hand the same object back

Looks good, what's wrong?
Writing to .values rewrites my input data! So, even my unsnapped optodes were magically snapped after calling snap_to_scalp_voxels, and an optode location comparison of before and after snapping showed no change at all 🤯

🐍 🐍 🐍

@emiddell emiddell merged commit 4e0208d into dev May 6, 2026
4 checks passed
@emiddell emiddell deleted the annoying-bug-fix branch May 6, 2026 04:34
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.

2 participants