Skip to content

Commit b72989d

Browse files
authored
Merge pull request #410 from djarecka/fix/numpy_hash
[fix] fixing hashing for numpy objects
2 parents a2ddfe7 + c0e0987 commit b72989d

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

pydra/engine/helpers.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ def hash_value(value, tp=None, metadata=None, precalculated=None):
673673
"""calculating hash or returning values recursively"""
674674
if metadata is None:
675675
metadata = {}
676-
if isinstance(value, (tuple, list)):
676+
if isinstance(value, (tuple, list, set)):
677677
return [hash_value(el, tp, metadata, precalculated) for el in value]
678678
elif isinstance(value, dict):
679679
dict_hash = {
@@ -694,8 +694,21 @@ def hash_value(value, tp=None, metadata=None, precalculated=None):
694694
and "container_path" not in metadata
695695
):
696696
return hash_dir(value, precalculated=precalculated)
697-
else:
697+
elif type(value).__module__ == "numpy": # numpy objects
698+
return sha256(value.tostring()).hexdigest()
699+
elif (
700+
isinstance(
701+
value, (int, float, complex, bool, str, bytes, LazyField, os.PathLike)
702+
)
703+
or value is None
704+
):
698705
return value
706+
else:
707+
warnings.warn(
708+
f"pydra doesn't fully support hashing for {type(value)}, "
709+
f"cp.dumps is used in hash functions, so it could depend on the system"
710+
)
711+
return sha256(cp.dumps(value)).hexdigest()
699712

700713

701714
def output_from_inputfields(output_spec, input_spec):

0 commit comments

Comments
 (0)