@@ -89,7 +89,7 @@ Example of using the text view.
8989 >>> t2 = {1 :1 , 3 :3 , 5 :5 , 6 :6 }
9090 >>> ddiff = DeepDiff(t1, t2)
9191 >>> print (ddiff)
92- {'dictionary_item_added': {' root[5]', ' root[6]'} , 'dictionary_item_removed': {' root[4]'} }
92+ {'dictionary_item_added': [ root[5], root[6]] , 'dictionary_item_removed': [ root[4]] }
9393
9494So for example ddiff['dictionary_item_removed'] is a set if strings thus this is called the text view.
9595
@@ -129,8 +129,8 @@ Item added and/or removed
129129 >>> t2 = {1 :1 , 3 :3 , 5 :5 , 6 :6 }
130130 >>> ddiff = DeepDiff(t1, t2)
131131 >>> pprint (ddiff)
132- {'dictionary_item_added': {' root[5]', ' root[6]'} ,
133- 'dictionary_item_removed': {' root[4]'} }
132+ {'dictionary_item_added': [ root[5], root[6]] ,
133+ 'dictionary_item_removed': [ root[4]] }
134134
135135Set verbose level to 2 in order to see the added or removed items with their values
136136 >>> t1 = {1 :1 , 3 :3 , 4 :4 }
@@ -230,15 +230,15 @@ List that contains dictionary:
230230 >>> t2 = {1 :1 , 2 :2 , 3 :3 , 4 :{" a" :" hello" , " b" :[1 , 2 , {1 :3 }]}}
231231 >>> ddiff = DeepDiff(t1, t2)
232232 >>> pprint (ddiff, indent = 2 )
233- { 'dictionary_item_removed': {" root[4]['b'][2][2]"} ,
233+ { 'dictionary_item_removed': [ root[4]['b'][2][2]] ,
234234 'values_changed': {"root[4]['b'][2][1]": {'new_value': 3, 'old_value': 1}}}
235235
236236Sets:
237237 >>> t1 = {1 , 2 , 8 }
238238 >>> t2 = {1 , 2 , 3 , 5 }
239239 >>> ddiff = DeepDiff(t1, t2)
240240 >>> pprint(ddiff)
241- {'set_item_added': {' root[5]', ' root[3]'} , 'set_item_removed': {' root[8]'} }
241+ {'set_item_added': [ root[3], root[5]] , 'set_item_removed': [ root[8]] }
242242
243243Named Tuples:
244244 >>> from collections import namedtuple
@@ -263,7 +263,7 @@ Custom objects:
263263Object attribute added:
264264 >>> t2.c = " new attribute"
265265 >>> pprint(DeepDiff(t1, t2))
266- {'attribute_added': {' root.c'} ,
266+ {'attribute_added': [ root.c] ,
267267 'values_changed': {'root.b': {'new_value': 2, 'old_value': 1}}}
268268
269269Approximate decimals comparison (Significant digits after the point):
@@ -272,7 +272,7 @@ Approximate decimals comparison (Significant digits after the point):
272272 >>> DeepDiff(t1, t2, significant_digits = 0 )
273273 {}
274274 >>> DeepDiff(t1, t2, significant_digits = 1 )
275- {'values_changed': {'root': {'old_value ': Decimal('1.52 '), 'new_value ': Decimal('1.57 ')}}}
275+ {'values_changed': {'root': {'new_value ': Decimal('1.57 '), 'old_value ': Decimal('1.52 ')}}}
276276
277277Approximate float comparison (Significant digits after the point):
278278 >>> t1 = [ 1.1129 , 1.3359 ]
@@ -354,9 +354,9 @@ Ignore Type Number - Dictionary that contains float and integer:
354354 >>> ddiff = DeepDiff(t1, t2)
355355 >>> pprint(ddiff, indent = 2 )
356356 { 'type_changes': { 'root[1]': { 'new_type': <class 'float'>,
357- 'new_value': 1.0,
358- 'old_type': <class 'int'>,
359- 'old_value': 1}}}
357+ 'new_value': 1.0,
358+ 'old_type': <class 'int'>,
359+ 'old_value': 1}}}
360360 >>> ddiff = DeepDiff(t1, t2, ignore_type_in_groups = DeepDiff.numbers)
361361 >>> pprint(ddiff, indent = 2 )
362362 {}
@@ -369,17 +369,17 @@ Ignore Type Number - List that contains float and integer:
369369 >>> ddiff = DeepDiff(t1, t2)
370370 >>> pprint(ddiff, indent = 2 )
371371 { 'type_changes': { 'root[0]': { 'new_type': <class 'float'>,
372- 'new_value': 1.0,
373- 'old_type': <class 'int'>,
374- 'old_value': 1},
375- 'root[1]': { 'new_type': <class 'float'>,
376- 'new_value': 2.0,
377- 'old_type': <class 'int'>,
378- 'old_value': 2},
379- 'root[2]': { 'new_type': <class 'float'>,
380- 'new_value': 3.0,
381- 'old_type': <class 'int'>,
382- 'old_value': 3}}}
372+ 'new_value': 1.0,
373+ 'old_type': <class 'int'>,
374+ 'old_value': 1},
375+ 'root[1]': { 'new_type': <class 'float'>,
376+ 'new_value': 2.0,
377+ 'old_type': <class 'int'>,
378+ 'old_value': 2},
379+ 'root[2]': { 'new_type': <class 'float'>,
380+ 'new_value': 3.0,
381+ 'old_type': <class 'int'>,
382+ 'old_value': 3}}}
383383 >>> ddiff = DeepDiff(t1, t2, ignore_type_in_groups = DeepDiff.numbers)
384384 >>> pprint(ddiff, indent = 2 )
385385 {}
@@ -469,11 +469,11 @@ Value of an item has changed (Tree View)
469469 >>> t2 = {1 :1 , 2 :4 , 3 :3 }
470470 >>> ddiff_verbose0 = DeepDiff(t1, t2, verbose_level = 0 , view = ' tree' )
471471 >>> ddiff_verbose0
472- {'values_changed': { <root[2]>} }
472+ {'values_changed': [ <root[2]>] }
473473 >>>
474474 >>> ddiff_verbose1 = DeepDiff(t1, t2, verbose_level = 1 , view = ' tree' )
475475 >>> ddiff_verbose1
476- {'values_changed': { <root[2] t1:2, t2:4>} }
476+ {'values_changed': [ <root[2] t1:2, t2:4>] }
477477 >>> set_of_values_changed = ddiff_verbose1[' values_changed' ]
478478 >>> # since set_of_values_changed includes only one item in a set
479479 >>> # in order to get that one item we can:
@@ -493,13 +493,13 @@ List difference (Tree View)
493493 >>> t2 = {1 :1 , 2 :2 , 3 :3 , 4 :{" a" :" hello" , " b" :[1 , 2 ]}}
494494 >>> ddiff = DeepDiff(t1, t2, view = ' tree' )
495495 >>> ddiff
496- {'iterable_item_removed': { <root[4]['b'][3 ] t1:4 , t2:Not Present >, <root[4]['b'][2 ] t1:3 , t2:Not Present>} }
496+ {'iterable_item_removed': [ <root[4]['b'][2 ] t1:3 , t2:not present >, <root[4]['b'][3 ] t1:4 , t2:not present>] }
497497 >>> # Note that the iterable_item_removed is a set. In this case it has 2 items in it.
498498 >>> # One way to get one item from the set is to convert it to a list
499499 >>> # And then get the first item of the list:
500500 >>> removed = list (ddiff[' iterable_item_removed' ])[0 ]
501501 >>> removed
502- <root[4]['b'][2] t1:3, t2:Not Present >
502+ <root[4]['b'][2] t1:3, t2:not present >
503503 >>>
504504 >>> parent = removed.up
505505 >>> parent
@@ -524,16 +524,15 @@ List difference 2 (Tree View)
524524 >>> t2 = {1 :1 , 2 :2 , 3 :3 , 4 :{" a" :" hello" , " b" :[1 , 3 , 2 , 3 ]}}
525525 >>> ddiff = DeepDiff(t1, t2, view = ' tree' )
526526 >>> pprint(ddiff, indent = 2 )
527- { 'iterable_item_added': {<root[4]['b'][3] t1:Not Present, t2:3>},
528- 'values_changed': { <root[4]['b'][1] t1:2, t2:3>,
529- <root[4]['b'][2] t1:3, t2:2>}}
527+ { 'iterable_item_added': [<root[4]['b'][3] t1:not present, t2:3>],
528+ 'values_changed': [<root[4]['b'][1] t1:2, t2:3>, <root[4]['b'][2] t1:3, t2:2>]}
530529 >>>
531530 >>> # Note that iterable_item_added is a set with one item.
532531 >>> # So in order to get that one item from it, we can do:
533532 >>>
534533 >>> (added,) = ddiff[' iterable_item_added' ]
535534 >>> added
536- <root[4]['b'][3] t1:Not Present , t2:3>
535+ <root[4]['b'][3] t1:not present , t2:3>
537536 >>> added.up.up
538537 <root[4] t1:{'a': 'hello...}, t2:{'a': 'hello...}>
539538 >>> added.up.up.path()
@@ -550,9 +549,8 @@ List difference ignoring order but reporting repetitions (Tree View)
550549 >>> t2 = [4 , 4 , 1 ]
551550 >>> ddiff = DeepDiff(t1, t2, ignore_order = True , report_repetition = True , view = ' tree' )
552551 >>> pprint(ddiff, indent = 2 )
553- { 'iterable_item_removed': {<root[1] t1:3, t2:Not Present>},
554- 'repetition_change': { <root[3] {'repetition': {'old_repeat': 1,...}>,
555- <root[0] {'repetition': {'old_repeat': 2,...}>}}
552+ { 'iterable_item_removed': [<root[1] t1:3, t2:not present>],
553+ 'repetition_change': [<root[3] {'repetition': {'old_repeat': 1,...}>, <root[0] {'repetition': {'old_repeat': 2,...}>]}
556554 >>>
557555 >>> # repetition_change is a set with 2 items.
558556 >>> # in order to get those 2 items, we can do the following.
@@ -561,15 +559,15 @@ List difference ignoring order but reporting repetitions (Tree View)
561559 >>>
562560 >>> (repeat1, repeat2) = ddiff[' repetition_change' ]
563561 >>> repeat1 # the default verbosity is set to 1.
564- <root[0 ] {'repetition': {'old_repeat': 2 ,...}>
562+ <root[3 ] {'repetition': {'old_repeat': 1 ,...}>
565563 >>> # The actual data regarding the repetitions can be found in the repetition attribute:
566564 >>> repeat1.repetition
567565 {'old_repeat': 1, 'new_repeat': 2, 'old_indexes': [3], 'new_indexes': [0, 1]}
568566 >>>
569567 >>> # If you change the verbosity, you will see less:
570568 >>> ddiff = DeepDiff(t1, t2, ignore_order = True , report_repetition = True , view = ' tree' , verbose_level = 0 )
571569 >>> ddiff
572- {'repetition_change': { <root[3]>, <root[0]>} , 'iterable_item_removed': { <root[1]>} }
570+ {'repetition_change': [ <root[3]>, <root[0]>] , 'iterable_item_removed': [ <root[1]>] }
573571 >>> (repeat1, repeat2) = ddiff[' repetition_change' ]
574572 >>> repeat1
575573 <root[0]>
@@ -590,15 +588,15 @@ List that contains dictionary (Tree View)
590588 >>> t2 = {1 :1 , 2 :2 , 3 :3 , 4 :{" a" :" hello" , " b" :[1 , 2 , {1 :3 }]}}
591589 >>> ddiff = DeepDiff(t1, t2, view = ' tree' )
592590 >>> pprint (ddiff, indent = 2 )
593- { 'dictionary_item_removed': { <root[4]['b'][2][2] t1:2, t2:Not Present>} ,
594- 'values_changed': { <root[4]['b'][2][1] t1:1, t2:3>} }
591+ { 'dictionary_item_removed': [ <root[4]['b'][2][2] t1:2, t2:not present>] ,
592+ 'values_changed': [ <root[4]['b'][2][1] t1:1, t2:3>] }
595593
596594Sets (Tree View):
597595 >>> t1 = {1 , 2 , 8 }
598596 >>> t2 = {1 , 2 , 3 , 5 }
599597 >>> ddiff = DeepDiff(t1, t2, view = ' tree' )
600598 >>> print (ddiff)
601- {'set_item_removed': { <root: t1:8, t2:Not Present>} , 'set_item_added': { <root: t1:Not Present , t2:5 >, <root: t1:Not Present , t2:3>} }
599+ {'set_item_removed': [ <root: t1:8, t2:not present>] , 'set_item_added': [ <root: t1:not present , t2:3 >, <root: t1:not present , t2:5>] }
602600 >>> # grabbing one item from set_item_removed set which has one item only
603601 >>> (item,) = ddiff[' set_item_removed' ]
604602 >>> item.up
@@ -612,7 +610,7 @@ Named Tuples (Tree View):
612610 >>> t1 = Point(x = 11 , y = 22 )
613611 >>> t2 = Point(x = 11 , y = 23 )
614612 >>> print (DeepDiff(t1, t2, view = ' tree' ))
615- {'values_changed': { <root.y t1:22, t2:23>} }
613+ {'values_changed': [ <root.y t1:22, t2:23>] }
616614
617615Custom objects (Tree View):
618616 >>> class ClassA (object ):
@@ -624,13 +622,13 @@ Custom objects (Tree View):
624622 >>> t2 = ClassA(2 )
625623 >>>
626624 >>> print (DeepDiff(t1, t2, view = ' tree' ))
627- {'values_changed': { <root.b t1:1, t2:2>} }
625+ {'values_changed': [ <root.b t1:1, t2:2>] }
628626
629627Object attribute added (Tree View):
630628 >>> t2.c = " new attribute"
631629 >>> pprint(DeepDiff(t1, t2, view = ' tree' ))
632- {'attribute_added': { <root.c t1:Not Present , t2:'new attribute'>} ,
633- 'values_changed': { <root.b t1:1, t2:2>} }
630+ {'attribute_added': [ <root.c t1:not present , t2:'new attribute'>] ,
631+ 'values_changed': [ <root.b t1:1, t2:2>] }
634632
635633Approximate decimals comparison (Significant digits after the point) (Tree View):
636634 >>> t1 = Decimal(' 1.52' )
@@ -639,7 +637,7 @@ Approximate decimals comparison (Significant digits after the point) (Tree View)
639637 {}
640638 >>> ddiff = DeepDiff(t1, t2, significant_digits = 1 , view = ' tree' )
641639 >>> ddiff
642- {'values_changed': { <root t1:Decimal('1.52'), t2:Decimal('1.57')>} }
640+ {'values_changed': [ <root t1:Decimal('1.52'), t2:Decimal('1.57')>] }
643641 >>> (change1,) = ddiff[' values_changed' ]
644642 >>> change1
645643 <root t1:Decimal('1.52'), t2:Decimal('1.57')>
@@ -658,11 +656,10 @@ Approximate float comparison (Significant digits after the point) (Tree View):
658656 {}
659657 >>> ddiff = DeepDiff(t1, t2, view = ' tree' )
660658 >>> pprint(ddiff, indent = 2 )
661- { 'values_changed': { <root[0] t1:1.1129, t2:1.113>,
662- <root[1] t1:1.3359, t2:1.3362>}}
659+ { 'values_changed': [<root[0] t1:1.1129, t2:1.113>, <root[1] t1:1.3359, t2:1.3362>]}
663660 >>> ddiff = DeepDiff(1.23 * 10 ** 20 , 1.24 * 10 ** 20 , significant_digits = 1 , view = ' tree' )
664661 >>> ddiff
665- {'values_changed': { <root t1:1.23e+20, t2:1.24e+20>} }
662+ {'values_changed': [ <root t1:1.23e+20, t2:1.24e+20>] }
666663
667664**Exclude paths **
668665
@@ -676,6 +673,7 @@ use `exclude_paths` and pass a set or list of paths to exclude, if only one item
676673 {}
677674
678675You can also exclude using regular expressions by using `exclude_regex_paths ` and pass a set or list of path regexes to exclude. The items in the list could be raw regex strings or compiled regex objects.
676+ >>> import re
679677 >>> t1 = [{' a' : 1 , ' b' : 2 }, {' c' : 4 , ' b' : 5 }]
680678 >>> t2 = [{' a' : 1 , ' b' : 3 }, {' c' : 4 , ' b' : 5 }]
681679 >>> print (DeepDiff(t1, t2, exclude_regex_paths = r " root\[ \d + \]\[ 'b'\] " ))
@@ -728,9 +726,9 @@ Serialize and then deserialize back to deepdiff
728726 >>> t1 = {1 : 1 , 2 : 2 , 3 : 3 }
729727 >>> t2 = {1 : 1 , 2 : " 2" , 3 : 3 }
730728 >>> ddiff = DeepDiff(t1, t2)
731- >>> jsoned = ddiff.to_json_pickle
729+ >>> jsoned = ddiff.to_json_pickle()
732730 >>> jsoned
733- '{"type_changes": {"root[2]": {"py/object": "dict", " new_type": {"py/type": "__builtin__ .str"}, "new_value": "2", "old_type": {"py/type": "__builtin__ .int"}, "old_value": 2}}}'
731+ '{"type_changes": {"root[2]": {"new_type": {"py/type": "builtins .str"}, "new_value": "2", "old_type": {"py/type": "builtins .int"}, "old_value": 2}}}'
734732 >>> ddiff_new = DeepDiff.from_json_pickle(jsoned)
735733 >>> ddiff == ddiff_new
736734 True
0 commit comments