Skip to content

Commit 70b9f09

Browse files
Added a manual overflow check when hashing int32's as older numpy versions don't seem to throw the exception.
1 parent ef85383 commit 70b9f09

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/emsarray/operations/cache.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@ def hash_int(hash: "hashlib._Hash", value: int) -> None:
6464
Expects an int that can be represented in a numpy int32.
6565
"""
6666
with numpy.errstate(over='raise'):
67-
hash.update(numpy.int32(value).tobytes())
67+
# Manual overflow check as older numpy versions dont throw the exception
68+
if numpy.iinfo("int32").min <= value <= numpy.iinfo("int32").max:
69+
hash.update(numpy.int32(value).tobytes())
70+
else:
71+
raise OverflowError
6872

6973

7074
def make_cache_key(dataset: xarray.Dataset, hash: "hashlib._Hash | None" = None) -> str:

0 commit comments

Comments
 (0)