diff options
author | Julien Duraj <julien.duraj@linaro.org> | 2019-08-29 15:11:50 +0100 |
---|---|---|
committer | Julien Duraj <julien.duraj@linaro.org> | 2019-09-03 14:13:57 +0000 |
commit | 46000dec33f451c3acebd1ffdf6c6ef9d11862b4 (patch) | |
tree | 3d4ca6bb3130063c525094eafeefb50acdce0671 | |
parent | 47ffe4210767e3101ab4563be2befebe9d95708a (diff) | |
download | art-testing-46000dec33f451c3acebd1ffdf6c6ef9d11862b4.tar.gz |
Fix KeepSameKeys function.
Check if both inputs are dictionaries, and print a warning if not.
Remove iteration on stats_type: the json/dictionary is flat, there is
no higher level stats type as this function was initially expecting.
Finally, since the operation is done in place, there is no need to
return the dictionaries again.
Change-Id: I1a8b4ca1c49523c1ab42cee0dff8faf931451ba9
-rwxr-xr-x | compare.py | 2 | ||||
-rw-r--r-- | tools/utils.py | 28 |
2 files changed, 16 insertions, 14 deletions
@@ -198,7 +198,7 @@ if __name__ == "__main__": filter_stats_warnings=args.output_for_linaro_automation) if not utils.HaveSameKeys(res_1, res_2): - res_1, res_2, diff = utils.KeepSameKeys(res_1, res_2) + diff = utils.KeepSameKeys(res_1, res_2) utils.Warning("Computing geomean on a subset of statistics which only " \ "includes keys common to both datasets.\n" \ "Removed Keys: " + str(diff)) diff --git a/tools/utils.py b/tools/utils.py index 5e6eb39..cf3144a 100644 --- a/tools/utils.py +++ b/tools/utils.py @@ -424,20 +424,22 @@ def Flatten(data, key=''): return res -# TODO: Refactor function to handle arbitrary data structures (see HaveSameKeys) def KeepSameKeys(data_1, data_2): - diff_keys_dict = dict() - for stats_type in data_1: - keys_1, keys_2 = data_1[stats_type].keys(), data_2[stats_type].keys() - diff_keys = keys_1 ^ keys_2 - diff_keys_dict[stats_type] = diff_keys - for k in list(keys_1): - if k in diff_keys: - del data_1[stats_type][k] - for k in list(keys_2): - if k in diff_keys: - del data_2[stats_type][k] - return data_1, data_2, diff_keys_dict + # This function makes little sense if inputs are not dictionaries. + if not IsDictionary(data_1) or not IsDictionary(data_2): + Warning("KeepSameKeys: an input object is not a dictionary. " \ + "Returning unchanged inputs with empty diff.") + return dict() + + keys_1, keys_2 = data_1.keys(), data_2.keys() + diff_keys = keys_1 ^ keys_2 + for k in list(keys_1): + if k in diff_keys: + del data_1[k] + for k in list(keys_2): + if k in diff_keys: + del data_2[k] + return diff_keys def HaveSameKeys(data_1, data_2): if IsDictionary(data_1) and IsDictionary(data_2): |