Skip to content

Commit d17c5c1

Browse files
Copilotmvdoc
andauthored
Handle NumPy 2.x hash compatibility for WebGL data (#584)
* Initial plan * Ensure numpy hash uses tobytes and add test Co-authored-by: mvdoc <[email protected]> * Rename braindata hash test file Co-authored-by: mvdoc <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: mvdoc <[email protected]>
1 parent d94db32 commit d17c5c1

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

cortex/dataset/braindata.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,7 @@ def __getitem__(self, masktype):
628628

629629
def _hash(array):
630630
'''A simple numpy hash function'''
631+
array = np.asarray(array)
631632
return hashlib.sha1(array.tobytes()).hexdigest()
632633

633634
def _hdf_write(h5, data, name="data", group="/data"):

cortex/tests/test_braindata.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import hashlib
2+
3+
import numpy as np
4+
5+
from cortex.dataset.braindata import _hash
6+
7+
8+
def test_hash_uses_tobytes():
9+
array = np.arange(12, dtype=np.float32).reshape(3, 4)
10+
expected = hashlib.sha1(array.tobytes()).hexdigest()
11+
assert _hash(array) == expected

0 commit comments

Comments
 (0)