Skip to content

Commit e5e1e4f

Browse files
authored
Merge pull request #419 from seperman/dev
6.5.0
2 parents 888ca77 + 54bee60 commit e5e1e4f

File tree

9 files changed

+80
-12
lines changed

9 files changed

+80
-12
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# DeepDiff v 6.4.1
1+
# DeepDiff v 6.5.0
22

33
![Downloads](https://img.shields.io/pypi/dm/deepdiff.svg?style=flat)
44
![Python Versions](https://img.shields.io/pypi/pyversions/deepdiff.svg?style=flat)
@@ -17,7 +17,7 @@
1717

1818
Tested on Python 3.7+ and PyPy3.
1919

20-
- **[Documentation](https://zepworks.com/deepdiff/6.4.1/)**
20+
- **[Documentation](https://zepworks.com/deepdiff/6.5.0/)**
2121

2222
## What is new?
2323

@@ -82,11 +82,11 @@ Thank you!
8282

8383
How to cite this library (APA style):
8484

85-
Dehpour, S. (2023). DeepDiff (Version 6.4.1) [Software]. Available from https://github.com/seperman/deepdiff.
85+
Dehpour, S. (2023). DeepDiff (Version 6.5.0) [Software]. Available from https://github.com/seperman/deepdiff.
8686

8787
How to cite this library (Chicago style):
8888

89-
Dehpour, Sep. 2023. DeepDiff (version 6.4.1).
89+
Dehpour, Sep. 2023. DeepDiff (version 6.5.0).
9090

9191
# Authors
9292

deepdiff/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""This module offers the DeepDiff, DeepSearch, grep, Delta and DeepHash classes."""
22
# flake8: noqa
3-
__version__ = '6.4.1'
3+
__version__ = '6.5.0'
44
import logging
55

66
if __name__ == '__main__':
@@ -11,4 +11,4 @@
1111
from .search import DeepSearch, grep
1212
from .deephash import DeepHash
1313
from .delta import Delta
14-
from .path import extract
14+
from .path import extract, parse_path

deepdiff/path.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,41 @@ def extract(obj, path):
185185
"""
186186
elements = _path_to_elements(path, root_element=None)
187187
return _get_nested_obj(obj, elements)
188+
189+
190+
def parse_path(path, root_element=DEFAULT_FIRST_ELEMENT, include_actions=False):
191+
"""
192+
Parse a path to a format that is machine readable
193+
194+
**Parameters**
195+
196+
path : A string
197+
The path string such as "root[1][2]['age']"
198+
199+
root_element: string, default='root'
200+
What the root is called in the path.
201+
202+
include_actions: boolean, default=False
203+
If True, we return the action required to retrieve the item at each element of the path.
204+
205+
**Examples**
206+
207+
>>> from deepdiff import parse_path
208+
>>> parse_path("root[1][2]['age']")
209+
[1, 2, 'age']
210+
>>> parse_path("root[1][2]['age']", include_actions=True)
211+
[{'element': 1, 'action': 'GET'}, {'element': 2, 'action': 'GET'}, {'element': 'age', 'action': 'GET'}]
212+
>>>
213+
>>> parse_path("root['joe'].age")
214+
['joe', 'age']
215+
>>> parse_path("root['joe'].age", include_actions=True)
216+
[{'element': 'joe', 'action': 'GET'}, {'element': 'age', 'action': 'GETATTR'}]
217+
218+
"""
219+
220+
result = _path_to_elements(path, root_element=root_element)
221+
result = iter(result)
222+
next(result) # We don't want the root item
223+
if include_actions is False:
224+
return [i[0] for i in result]
225+
return [{'element': i[0], 'action': i[1]} for i in result]

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@
6161
# built documents.
6262
#
6363
# The short X.Y version.
64-
version = '6.4.1'
64+
version = '6.5.0'
6565
# The full version, including alpha/beta/rc tags.
66-
release = '6.4.1'
66+
release = '6.5.0'
6767

6868
load_dotenv(override=True)
6969
DOC_VERSION = os.environ.get('DOC_VERSION', version)

docs/faq.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,23 @@ In order to serialize DeepDiff results into json, use to_json()
8888
>>> diff.to_json()
8989
'{"type_changes": {"root": {"old_type": "int", "new_type": "str", "old_value": 1, "new_value": "a"}}}'
9090

91+
92+
Q: How do I parse DeepDiff result paths?
93+
----------------------------------------
94+
95+
**Answer**
96+
97+
Use parse_path:
98+
99+
>>> from deepdiff import parse_path
100+
>>> parse_path("root[1][2]['age']")
101+
[1, 2, 'age']
102+
>>> parse_path("root[1][2]['age']", include_actions=True)
103+
[{'element': 1, 'action': 'GET'}, {'element': 2, 'action': 'GET'}, {'element': 'age', 'action': 'GET'}]
104+
>>>
105+
>>> parse_path("root['joe'].age")
106+
['joe', 'age']
107+
>>> parse_path("root['joe'].age", include_actions=True)
108+
[{'element': 'joe', 'action': 'GET'}, {'element': 'age', 'action': 'GETATTR'}]
109+
91110
Back to :doc:`/index`

docs/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
contain the root `toctree` directive.
55
66
7-
DeepDiff 6.4.1 documentation!
7+
DeepDiff 6.5.0 documentation!
88
=============================
99

1010
*******

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 6.4.1
2+
current_version = 6.5.0
33
commit = True
44
tag = True
55
tag_name = {new_version}

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
if os.environ.get('USER', '') == 'vagrant':
1111
del os.link
1212

13-
version = '6.4.1'
13+
version = '6.5.0'
1414

1515

1616
def get_reqs(filename):

tests/test_path.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import pytest
2-
from deepdiff.path import _path_to_elements, GET, GETATTR, extract
2+
from deepdiff.path import _path_to_elements, GET, GETATTR, extract, parse_path
33

44

55
@pytest.mark.parametrize('path, expected', [
@@ -32,3 +32,14 @@ def test_path_to_elements(path, expected):
3232
def test_get_item(obj, path, expected):
3333
result = extract(obj, path)
3434
assert expected == result
35+
36+
37+
def test_parse_path():
38+
result = parse_path("root[1][2]['age']")
39+
assert [1, 2, 'age'] == result
40+
result2 = parse_path("root[1][2]['age']", include_actions=True)
41+
assert [{'element': 1, 'action': 'GET'}, {'element': 2, 'action': 'GET'}, {'element': 'age', 'action': 'GET'}] == result2
42+
result3 = parse_path("root['joe'].age")
43+
assert ['joe', 'age'] == result3
44+
result4 = parse_path("root['joe'].age", include_actions=True)
45+
assert [{'element': 'joe', 'action': 'GET'}, {'element': 'age', 'action': 'GETATTR'}] == result4

0 commit comments

Comments
 (0)