Skip to content
Snippets Groups Projects
Commit c742d8c0 authored by Thomas Jürges's avatar Thomas Jürges
Browse files

Task SSB-42: Added a dict comparison function

parent 10d405d5
No related branches found
No related tags found
1 merge request!44Merge back holography to master
......@@ -58,6 +58,20 @@ class HolographyDataset():
# ('flag', numpy.bool)]
# )
@staticmethod
def compare_dicts(dict1, dict2):
result = True
for key in dict1.keys():
if key in dict2.keys():
if isinstance(dict1[key], dict) and isinstance(dict2[key], dict):
result = result and HolographyDataset.compare_dicts(dict1[key], dict2[key])
else:
return dict1[key] == dict2[key]
else:
print(key, dict1.keys(), dict2.keys())
return False
return result
def __eq__(self, hds = None):
equality = False
if hds is not None and isinstance(hds, HolographyDataset) is True:
......@@ -68,6 +82,8 @@ class HolographyDataset():
try:
if isinstance(attribute_value, numpy.ndarray) is True and isinstance(other_value, numpy.ndarray) is True:
this_equality = numpy.array_equal(attribute_value, other_value)
elif isinstance(attribute_value, dict) is True and isinstance(other_value, dict) is True:
this_equality = HolographyDataset.compare_dicts(attribute_value, other_value)
elif attribute_value != other_value:
this_equality = False
except Exception as e:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment