Skip to content

Commit 8ab3925

Browse files
committed
updating version
1 parent 62b1e80 commit 8ab3925

File tree

4 files changed

+108
-65
lines changed

4 files changed

+108
-65
lines changed

README.md

Lines changed: 95 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ Tested on Python 2.7, 3.3, 3.4, 3.5, Pypy, Pypy3
1212
## Table of Contents
1313

1414
- [Installation](#Installation)
15-
- [Importing](#Importing)
16-
- [Supported data types](#supported-data-types)
17-
- [Type Change](#type-of-an-item-has-changed)
18-
- [Value Change](#value-of-an-item-has-changed)
19-
- [Item added or removed](#item-added-or-removed)
20-
- [String difference](#string-difference)
15+
- [Parameters](#parameters)
16+
- [Ignore Order](#ignore-order)
17+
- [Report repetitions](#report-repetitions)
18+
- [Verbose Level](#verbose-level)
19+
- [Examples](#examples)
20+
- [Documentation](http://deepdiff.readthedocs.io/en/latest/)
21+
2122

2223
##Installation
2324

@@ -31,10 +32,67 @@ Tested on Python 2.7, 3.3, 3.4, 3.5, Pypy, Pypy3
3132
>>> from deepdiff import DeepDiff
3233
```
3334

35+
## Parameters
36+
37+
In addition to the 2 objects being compared:
38+
39+
- [ignore_order](#ignore-order)
40+
- [report_repetition](#report-repetitions)
41+
- [verbose_level](#verbose-level)
42+
3443
## Supported data types
3544

3645
int, string, dictionary, list, tuple, set, frozenset, OrderedDict, NamedTuple and custom objects!
3746

47+
## Ignore Order
48+
49+
Sometimes you don't care about the order of objects when comparing them. In those cases, you can set `ignore_order=True`. However this flag won't report the repetitions to you. You need to additionally enable `report_report_repetition=True` for getting a report of repetitions.
50+
51+
### List difference ignoring order or duplicates
52+
53+
```python
54+
>>> t1 = {1:1, 2:2, 3:3, 4:{"a":"hello", "b":[1, 2, 3]}}
55+
>>> t2 = {1:1, 2:2, 3:3, 4:{"a":"hello", "b":[1, 3, 2, 3]}}
56+
>>> ddiff = DeepDiff(t1, t2, ignore_order=True)
57+
>>> print (ddiff)
58+
{}
59+
```
60+
61+
## Report repetitions
62+
63+
This flag ONLY works when ignoring order is enabled.
64+
65+
```python
66+
t1 = [1, 3, 1, 4]
67+
t2 = [4, 4, 1]
68+
ddiff = DeepDiff(t1, t2, ignore_order=True, report_repetition=True)
69+
print(ddiff)
70+
```
71+
72+
which will print you:
73+
74+
```python
75+
{'iterable_item_removed': {'root[1]': 3},
76+
'repetition_change': {'root[0]': {'old_repeat': 2,
77+
'old_indexes': [0, 2],
78+
'new_indexes': [2],
79+
'value': 1,
80+
'new_repeat': 1},
81+
'root[3]': {'old_repeat': 1,
82+
'old_indexes': [3],
83+
'new_indexes': [0, 1],
84+
'value': 4,
85+
'new_repeat': 2}}}
86+
```
87+
88+
## Verbose Level
89+
90+
Verbose level by default is 1. The possible values are 0, 1 and 2.
91+
92+
- Verbose level 0: won't report values when type changed. [Example](##type-of-an-item-has-changed)
93+
- Verbose level 1: default
94+
- Verbose level 2: will report values when custom objects or dictionaries have items added or removed. [Example](#items-added-or-removed-verbose)
95+
3896

3997
## Examples
4098

@@ -67,6 +125,17 @@ int, string, dictionary, list, tuple, set, frozenset, OrderedDict, NamedTuple an
67125
'old_value': 2}}}
68126
```
69127

128+
And if you don't care about the value of items that have changed type, please set verbose level to 0:
129+
130+
```python
131+
>>> t1 = {1:1, 2:2, 3:3}
132+
>>> t2 = {1:1, 2:"2", 3:3}
133+
>>> pprint(DeepDiff(t1, t2), indent=2)
134+
{ 'type_changes': { 'root[2]': { 'new_type': <class 'str'>,
135+
'old_type': <class 'int'>,}}}
136+
```
137+
138+
70139
### Value of an item has changed
71140

72141
```python
@@ -79,13 +148,25 @@ int, string, dictionary, list, tuple, set, frozenset, OrderedDict, NamedTuple an
79148
### Item added or removed
80149

81150
```python
82-
>>> t1 = {1:1, 2:2, 3:3, 4:4}
83-
>>> t2 = {1:1, 2:4, 3:3, 5:5, 6:6}
151+
>>> t1 = {1:1, 3:3, 4:4}
152+
>>> t2 = {1:1, 3:3, 5:5, 6:6}
84153
>>> ddiff = DeepDiff(t1, t2)
85-
>>> pprint (ddiff)
86-
{'dictionary_item_added': ['root[5]', 'root[6]'],
87-
'dictionary_item_removed': ['root[4]'],
88-
'values_changed': {'root[2]': {'new_value': 4, 'old_value': 2}}}
154+
>>> pprint(ddiff)
155+
{'dictionary_item_added': {'root[5]', 'root[6]'},
156+
'dictionary_item_removed': {'root[4]'}}
157+
```
158+
159+
#### Items added or removed verbose
160+
161+
And if you would like to know the values of items added or removed, please set the verbose_level to 2:
162+
163+
```python
164+
>>> t1 = {1:1, 3:3, 4:4}
165+
>>> t2 = {1:1, 3:3, 5:5, 6:6}
166+
>>> ddiff = DeepDiff(t1, t2, verbose_level=2)
167+
>>> pprint(ddiff, indent=2)
168+
{ 'dictionary_item_added': {'root[5]': 5, 'root[6]': 6},
169+
'dictionary_item_removed': {'root[4]': 4}}
89170
```
90171

91172
### String difference
@@ -136,19 +217,6 @@ int, string, dictionary, list, tuple, set, frozenset, OrderedDict, NamedTuple an
136217
End
137218
```
138219

139-
### Type change
140-
141-
```python
142-
>>> t1 = {1:1, 2:2, 3:3, 4:{"a":"hello", "b":[1, 2, 3]}}
143-
>>> t2 = {1:1, 2:2, 3:3, 4:{"a":"hello", "b":"world\n\n\nEnd"}}
144-
>>> ddiff = DeepDiff(t1, t2)
145-
>>> pprint (ddiff, indent = 2)
146-
{ 'type_changes': { "root[4]['b']": { 'new_type': <class 'str'>,
147-
'new_value': 'world\n\n\nEnd',
148-
'old_type': <class 'list'>,
149-
'old_value': [1, 2, 3]}}}
150-
```
151-
152220
### List difference
153221

154222
```python
@@ -159,7 +227,7 @@ int, string, dictionary, list, tuple, set, frozenset, OrderedDict, NamedTuple an
159227
{'iterable_item_removed': {"root[4]['b'][2]": 3, "root[4]['b'][3]": 4}}
160228
```
161229

162-
### List difference 2:
230+
### List difference Example 2
163231

164232
```python
165233
>>> t1 = {1:1, 2:2, 3:3, 4:{"a":"hello", "b":[1, 2, 3]}}
@@ -171,38 +239,6 @@ int, string, dictionary, list, tuple, set, frozenset, OrderedDict, NamedTuple an
171239
"root[4]['b'][2]": {'new_value': 2, 'old_value': 3}}}
172240
```
173241

174-
### List difference ignoring order or duplicates: (with the same dictionaries as above)
175-
176-
```python
177-
>>> t1 = {1:1, 2:2, 3:3, 4:{"a":"hello", "b":[1, 2, 3]}}
178-
>>> t2 = {1:1, 2:2, 3:3, 4:{"a":"hello", "b":[1, 3, 2, 3]}}
179-
>>> ddiff = DeepDiff(t1, t2, ignore_order=True)
180-
>>> print (ddiff)
181-
{}
182-
```
183-
184-
### List difference ignoring order or duplicates for objects that have hash collision (Advanced)
185-
186-
It might rarely happen that Python objects have hash collision using the built-in hash function:
187-
188-
```python
189-
>>> a='\0B'
190-
>>> hash(a)
191-
64
192-
>>> b='\0\0C'
193-
>>> hash(b)
194-
64
195-
```
196-
197-
Although `ignore_order` flag uses hash of items to calculate what is added or removed, we still get the right answer.
198-
199-
```python
200-
>>> list1=[a,b]
201-
>>> list2=[a,a]
202-
>>> DeepDiff(list1,list2, ignore_order=True)
203-
{'set_item_removed': set(["root['\x00\x00C']"])}
204-
```
205-
206242
### List that contains dictionary:
207243

208244
```python
@@ -341,7 +377,7 @@ And here is more info: <http://zepworks.com/blog/diff-it-to-digg-it/>
341377

342378
##Documentation
343379

344-
<http://deepdiff.readthedocs.org/en/latest/>
380+
<http://deepdiff.readthedocs.io/en/latest/>
345381

346382
##Changelog
347383

README.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ http://zepworks.com/blog/diff-it-to-digg-it/
1515

1616
**Parameters**
1717

18-
t1 : A dictionary, list, string or any python object that has __dict__
19-
This is the first item to be compared to the second item
18+
In addition to the 2 objects being compared:
2019

21-
t2 : dictionary, list, string or almost any python object that has __dict__
22-
The second item is to be compared to the first one
20+
- ignore_order
21+
- report_repetition
22+
- verbose_level
2323

2424
**Returns**
2525

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
long_description = "Deep Difference of dictionaries, iterables, strings and other objects. It will recursively look for all the changes."
1414

1515
setup(name='deepdiff',
16-
version='1.8.0',
16+
version='2.0.0',
1717
description='Deep Difference of dictionaries, iterables, strings and other objects. It will recursively look for all the changes.',
1818
url='https://github.com/seperman/deepdiff',
1919
download_url='https://github.com/seperman/deepdiff/tarball/master',

tests.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,20 @@ def test_same_objects(self):
4040
t2 = t1
4141
self.assertEqual(DeepDiff(t1, t2), {})
4242

43-
def test_item_change(self):
43+
def test_item_type_change(self):
4444
t1 = {1: 1, 2: 2, 3: 3}
4545
t2 = {1: 1, 2: "2", 3: 3}
4646
self.assertEqual(DeepDiff(t1, t2), {'type_changes': {"root[2]":
4747
{"old_value": 2, "old_type": int,
4848
"new_value": "2", "new_type": str}}})
4949

50+
def test_item_type_change_less_verbose(self):
51+
t1 = {1: 1, 2: 2, 3: 3}
52+
t2 = {1: 1, 2: "2", 3: 3}
53+
self.assertEqual(DeepDiff(t1, t2, verbose_level=0), {'type_changes': {"root[2]":
54+
{"old_type": int,
55+
"new_type": str}}})
56+
5057
def test_value_change(self):
5158
t1 = {1: 1, 2: 2, 3: 3}
5259
t2 = {1: 1, 2: 4, 3: 3}

0 commit comments

Comments
 (0)