Skip to content

Commit e8fd305

Browse files
committed
Merge branch 'dev' of github.com:seperman/deepdiff into dev
2 parents 8f51a34 + fe70fa0 commit e8fd305

File tree

3 files changed

+93
-45
lines changed

3 files changed

+93
-45
lines changed

deepdiff/diff.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -854,13 +854,15 @@ def _diff_by_forming_pairs_and_comparing_one_by_one(
854854
if self._count_diff() is StopIteration:
855855
return # pragma: no cover. This is already covered for addition.
856856

857+
reference_param1 = i
858+
reference_param2 = j
857859
if y is ListItemRemovedOrAdded: # item removed completely
858860
change_level = level.branch_deeper(
859861
x,
860862
notpresent,
861863
child_relationship_class=child_relationship_class,
862-
child_relationship_param=i,
863-
child_relationship_param2=j,
864+
child_relationship_param=reference_param1,
865+
child_relationship_param2=reference_param2,
864866
)
865867
self._report_result('iterable_item_removed', change_level, local_tree=local_tree)
866868

@@ -869,8 +871,8 @@ def _diff_by_forming_pairs_and_comparing_one_by_one(
869871
notpresent,
870872
y,
871873
child_relationship_class=child_relationship_class,
872-
child_relationship_param=i,
873-
child_relationship_param2=j,
874+
child_relationship_param=reference_param1,
875+
child_relationship_param2=reference_param2,
874876
)
875877
self._report_result('iterable_item_added', change_level, local_tree=local_tree)
876878

@@ -881,11 +883,17 @@ def _diff_by_forming_pairs_and_comparing_one_by_one(
881883
x,
882884
y,
883885
child_relationship_class=child_relationship_class,
884-
child_relationship_param=i,
885-
child_relationship_param2=j
886+
child_relationship_param=reference_param1,
887+
child_relationship_param2=reference_param2
886888
)
887889
self._report_result('iterable_item_moved', change_level, local_tree=local_tree)
888-
continue
890+
891+
if self.iterable_compare_func:
892+
# Intentionally setting j as the first child relationship param in cases of a moved item.
893+
# If the item was moved using an iterable_compare_func then we want to make sure that the index
894+
# is relative to t2.
895+
reference_param1 = j
896+
reference_param2 = i
889897

890898
item_id = id(x)
891899
if parents_ids and item_id in parents_ids:
@@ -897,8 +905,8 @@ def _diff_by_forming_pairs_and_comparing_one_by_one(
897905
x,
898906
y,
899907
child_relationship_class=child_relationship_class,
900-
child_relationship_param=i,
901-
child_relationship_param2=j,
908+
child_relationship_param=reference_param1,
909+
child_relationship_param2=reference_param2
902910
)
903911
self._diff(next_level, parents_ids_added, local_tree=local_tree)
904912

Lines changed: 53 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,59 @@
11
{
2-
"dictionary_item_added": [
3-
"root['Cars'][3]['dealers']"
4-
],
5-
"dictionary_item_removed": [
6-
"root['Cars'][3]['production']"
7-
],
8-
"values_changed": {
9-
"root['Cars'][3]['model']": {
10-
"new_value": "Supra",
11-
"old_value": "supra"
12-
}
2+
"dictionary_item_added": [
3+
"root['Cars'][3]['dealers']"
4+
],
5+
"dictionary_item_removed": [
6+
"root['Cars'][3]['production']"
7+
],
8+
"values_changed": {
9+
"root['Cars'][2]['dealers'][0]['quantity']": {
10+
"new_value": 50,
11+
"old_value": 20
1312
},
14-
"iterable_item_added": {
15-
"root['Cars'][0]": {
16-
"id": "7",
17-
"make": "Toyota",
18-
"model": "8Runner"
19-
}
13+
"root['Cars'][1]['model_numbers'][2]": {
14+
"new_value": 3,
15+
"old_value": 4
16+
},
17+
"root['Cars'][3]['model']": {
18+
"new_value": "Supra",
19+
"old_value": "supra"
20+
}
21+
},
22+
"iterable_item_added": {
23+
"root['Cars'][2]['dealers'][1]": {
24+
"id": 200,
25+
"address": "200 Fake St",
26+
"quantity": 10
27+
},
28+
"root['Cars'][1]['model_numbers'][3]": 4,
29+
"root['Cars'][0]": {
30+
"id": "7",
31+
"make": "Toyota",
32+
"model": "8Runner"
33+
}
34+
},
35+
"iterable_item_removed": {
36+
"root['Cars'][2]['dealers'][0]": {
37+
"id": 103,
38+
"address": "103 Fake St",
39+
"quantity": 50
2040
},
21-
"iterable_item_removed": {
22-
"root['Cars'][1]": {
23-
"id": "2",
24-
"make": "Toyota",
25-
"model": "Highlander",
26-
"dealers": [
27-
{
28-
"id": 123,
29-
"address": "123 Fake St",
30-
"quantity": 50
31-
},
32-
{
33-
"id": 125,
34-
"address": "125 Fake St",
35-
"quantity": 20
36-
}
37-
]
41+
"root['Cars'][1]": {
42+
"id": "2",
43+
"make": "Toyota",
44+
"model": "Highlander",
45+
"dealers": [
46+
{
47+
"id": 123,
48+
"address": "123 Fake St",
49+
"quantity": 50
50+
},
51+
{
52+
"id": 125,
53+
"address": "125 Fake St",
54+
"quantity": 20
3855
}
56+
]
3957
}
58+
}
4059
}

tests/test_delta.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1894,7 +1894,14 @@ def test_compare_func_with_duplicates_removed(self):
18941894
"val": 3
18951895
}
18961896
}
1897-
}
1897+
},
1898+
'values_changed': {
1899+
"root[2]['val']": {
1900+
'new_value': 3,
1901+
'old_value': 1,
1902+
'new_path': "root[0]['val']"
1903+
}
1904+
},
18981905
}
18991906
assert expected == ddiff
19001907
delta = Delta(ddiff)
@@ -1903,6 +1910,7 @@ def test_compare_func_with_duplicates_removed(self):
19031910

19041911
flat_result = delta.to_flat_rows()
19051912
flat_expected = [
1913+
{'path': [2, 'val'], 'value': 3, 'action': 'values_changed', 'type': int, 'new_path': [0, 'val']},
19061914
{'path': [2], 'value': {'id': 1, 'val': 3}, 'action': 'iterable_item_removed', 'type': dict},
19071915
{'path': [0], 'value': {'id': 1, 'val': 3}, 'action': 'iterable_item_removed', 'type': dict},
19081916
{'path': [3], 'value': {'id': 3, 'val': 3}, 'action': 'iterable_item_removed', 'type': dict},
@@ -1945,6 +1953,12 @@ def test_compare_func_with_duplicates_removed(self):
19451953
'val': 3
19461954
}
19471955
}
1956+
},
1957+
'values_changed': {
1958+
"root[2]['val']": {
1959+
'new_value': 3,
1960+
'new_path': "root[0]['val']"
1961+
}
19481962
}
19491963
}
19501964
assert expected_delta_dict == delta_again.diff
@@ -1976,7 +1990,14 @@ def test_compare_func_with_duplicates_added(self):
19761990
'val': 1
19771991
}
19781992
}
1979-
}
1993+
},
1994+
'values_changed': {
1995+
"root[0]['val']": {
1996+
'new_value': 1,
1997+
'old_value': 3,
1998+
'new_path': "root[2]['val']"
1999+
}
2000+
},
19802001
}
19812002
assert expected == ddiff
19822003
delta = Delta(ddiff)

0 commit comments

Comments
 (0)