Skip to content

Commit

Permalink
fixing hashing for numpy objects str from numpy array doesnt work wel…
Browse files Browse the repository at this point in the history
…l (doesnt return all of the elements); adding cp.dumps for other complex objects
  • Loading branch information
djarecka committed Feb 13, 2021
1 parent 480fd58 commit c0e0987
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions pydra/engine/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ def hash_value(value, tp=None, metadata=None, precalculated=None):
"""calculating hash or returning values recursively"""
if metadata is None:
metadata = {}
if isinstance(value, (tuple, list)):
if isinstance(value, (tuple, list, set)):
return [hash_value(el, tp, metadata, precalculated) for el in value]
elif isinstance(value, dict):
dict_hash = {
Expand All @@ -694,8 +694,21 @@ def hash_value(value, tp=None, metadata=None, precalculated=None):
and "container_path" not in metadata
):
return hash_dir(value, precalculated=precalculated)
else:
elif type(value).__module__ == "numpy": # numpy objects
return sha256(value.tostring()).hexdigest()
elif (
isinstance(
value, (int, float, complex, bool, str, bytes, LazyField, os.PathLike)
)
or value is None
):
return value
else:
warnings.warn(
f"pydra doesn't fully support hashing for {type(value)}, "
f"cp.dumps is used in hash functions, so it could depend on the system"
)
return sha256(cp.dumps(value)).hexdigest()


def output_from_inputfields(output_spec, input_spec):
Expand Down

0 comments on commit c0e0987

Please sign in to comment.