seperman / deepdiff

DeepDiff: Deep Difference and search of any Python object/data. DeepHash: Hash of any object based on its contents. Delta: Use deltas to reconstruct objects by adding deltas together.
http://zepworks.com
Other
2.03k stars 224 forks source link

Consistent root structure #498

Closed AntonioONS closed 3 weeks ago

AntonioONS commented 3 weeks ago

Is your feature request related to a problem? Please describe. We're currently trying to use DeepDiff to compare the outputs of 2 models we've created (old and new) and running this process on a bulk load of outputs iteratively (run case XYZ on old and new model and compare the outputs). The issue is that the level of difference between the outputs can vary (sometimes just 1-5 elements are different, sometimes nested dicts are different, we're trying to find and solve them all), with these differences, we then sometimes get just a singular "root" variable (when we have more nested dict differences with a single dict output for old and new values) and other times we get a list of "root[X][Y][Z]" when there are fewer differences. These differences in outputs mess with our automated process to compare the outputs.

Describe the solution you'd like Can we have a single and enforced "root" structure (preferably the singular "root") and a way to call it consistently (as an input argument to DeepDiff perhaps)? So instead of getting root[X]][Y][Z]: {old_val, new_val}, I want it to consistently produce root: {old_val{X:{Y:{Z:}}}, new_val{X:{Y:{Z:}}}}

Describe alternatives you've considered I'm trying to restructure the process myself, but running into issues since the multiple roots can have different depths and also doesn't break out the old and new values as I need currently:

try: # for the case of there being muliple roots
    keys_to_rename = diff.affected_root_keys
    diff = json.loads(diff.to_json())
    for group in diff:
        for key in diff[group]:
            for name in keys_to_rename:
                if name in key:
                    diff[group][name] = diff[group].pop(key)
                    break
        diff[group]['root'] = {}
        for name in keys_to_rename:
            diff[group]['root'][name] = diff[group].pop(name)
except AttributeError: # affected_root_keys will error when there's only one root
    diff = json.loads(diff.to_json())

Additional context We can't just go straight to text since there are certain core keys we look out for changes on and less important keys that we want to track but aren't needed, for this we just need a consistent output strucuture.

seperman commented 3 weeks ago

@AntonioONS Have you looked into the tree view? It gives you way more flexibility to do what you need.