parse_path() cannot parse a path
novns opened this issue ยท 4 comments
novns commented
A path produced by DeepDiff() cannot be parsed with parse_path():
>>> diff = deepdiff.DeepDiff({'Key': set([1, 2])} , {'Key': set([2])})
>>> diff
{'set_item_removed': [root['Key'][1]]}
>>> path = diff['set_item_removed']
>>> path
[root['Key'][1]]
>>> deepdiff.parse_path(path)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File ".../venv/lib/python3.11/site-packages/deepdiff/path.py", line 262, in parse_path
result = _path_to_elements(path, root_element=root_element)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: unhashable type: 'PrettyOrderedSet'
Python 3.11, deepdiff 6.7.1
anddam commented
From help(deepdiff.parse_path)
**Parameters**
path : A string
The path string such as "root[1][2]['age']"
use parse_path(str(path))
novns commented
deepdiff.parse_path(str(path))
works.
The documentation could be improved for clarity.
novns commented
Using str is wrong because path
is a PrettyOrderedSet
of paths.
The correct way would be using deepdiff.parse_path(path[0])
or iterate through all paths
seperman commented
Hi @novns and @anddam
You may want to use the "tree view" instead of the "text view".
https://zepworks.com/deepdiff/current/view.html#tree-view