diff options
author | BonfaceKilz | 2022-03-14 18:06:02 +0300 |
---|---|---|
committer | BonfaceKilz | 2022-03-14 18:06:02 +0300 |
commit | a41948ee07eb149885000927267c95eb1e1c64c1 (patch) | |
tree | 32c97d510f9d6238eb534ebdceb639fff2c3766f /gn3 | |
parent | a8c3e35cc80bf14ba40a136bb54e8850d23c0065 (diff) | |
download | genenetwork3-a41948ee07eb149885000927267c95eb1e1c64c1.tar.gz |
Only loop through the diff's modifications if it exists
Diffstat (limited to 'gn3')
-rw-r--r-- | gn3/csvcmp.py | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/gn3/csvcmp.py b/gn3/csvcmp.py index dd3f72b..975814a 100644 --- a/gn3/csvcmp.py +++ b/gn3/csvcmp.py @@ -26,24 +26,25 @@ def create_dirs_if_not_exists(dirs: list) -> None: def remove_insignificant_edits(diff_data, epsilon=0.001): """Remove or ignore edits that are not within ε""" __mod = [] - for mod in diff_data.get("Modifications"): - original = mod.get("Original").split(",") - current = mod.get("Current").split(",") - for i, (_x, _y) in enumerate(zip(original, current)): - if ( - _x.replace(".", "").isdigit() - and _y.replace(".", "").isdigit() - and abs(float(_x) - float(_y)) < epsilon - ): - current[i] = _x - if not (__o := ",".join(original)) == (__c := ",".join(current)): - __mod.append( - { - "Original": __o, - "Current": __c, - } - ) - diff_data["Modifications"] = __mod + if diff_data.get("Modifications"): + for mod in diff_data.get("Modifications"): + original = mod.get("Original").split(",") + current = mod.get("Current").split(",") + for i, (_x, _y) in enumerate(zip(original, current)): + if ( + _x.replace(".", "").isdigit() + and _y.replace(".", "").isdigit() + and abs(float(_x) - float(_y)) < epsilon + ): + current[i] = _x + if not (__o := ",".join(original)) == (__c := ",".join(current)): + __mod.append( + { + "Original": __o, + "Current": __c, + } + ) + diff_data["Modifications"] = __mod return diff_data |