Skip to content

Commit 6660846

Browse files
Copilotmvdoc
andcommitted
Ensure numpy hash uses tobytes and add test
Co-authored-by: mvdoc <[email protected]>
1 parent 69e783e commit 6660846

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"):
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)