Handle NumPy 2.x hash compatibility for WebGL data#584
Merged
Conversation
Co-authored-by: mvdoc <6150554+mvdoc@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix numpy.ndarray attribute error in WebGL usage
Handle NumPy 2.x hash compatibility for WebGL data
Dec 12, 2025
mvdoc
requested changes
Dec 12, 2025
Contributor
There was a problem hiding this comment.
Rename this to test_braindata.py; hopefully we can add more tests in the future
Contributor
Author
There was a problem hiding this comment.
Renamed to test_braindata.py in bfb0e22 to keep room for additional cases.
Co-authored-by: mvdoc <6150554+mvdoc@users.noreply.github.com>
mvdoc
approved these changes
Dec 12, 2025
There was a problem hiding this comment.
Pull request overview
This PR fixes a compatibility issue with NumPy ≥2.2 where ndarray.tostring() was removed, causing WebGL view initialization to crash when hashing brain data arrays.
- Updated
_hash()function to usetobytes()instead of the deprecatedtostring()method - Added
np.asarray()coercion to ensure inputs are converted to NumPy arrays before hashing - Added regression test to verify correct hashing behavior
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| cortex/dataset/braindata.py | Fixed _hash() function to use tobytes() and added array coercion with np.asarray() for NumPy 2.x compatibility |
| cortex/tests/test_braindata.py | Added test to verify _hash() correctly uses tobytes() and matches expected SHA1 hash output |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
WebGL data hashing failed on NumPy ≥2.2 because
ndarray.tostring()was removed, causing WebGL view initialization to crash when hashing brain data arrays.tobytes()inbraindata._hashto restore compatibility with modern NumPy.cortex/tests/test_braindata.pythat asserts_hashmatcheshashlib.sha1(array.tobytes())for NumPy arrays.Example:
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.