From c0e0987f85e97ebf0f95b04be0841c7690c61cfd Mon Sep 17 00:00:00 2001 From: Dorota Jarecka Date: Sat, 13 Feb 2021 00:26:23 -0500 Subject: [PATCH] fixing hashing for numpy objects str from numpy array doesnt work well (doesnt return all of the elements); adding cp.dumps for other complex objects --- pydra/engine/helpers.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/pydra/engine/helpers.py b/pydra/engine/helpers.py index 1ebd2c4e7b..632a1fbb6b 100644 --- a/pydra/engine/helpers.py +++ b/pydra/engine/helpers.py @@ -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 = { @@ -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):