Skip to content

Commit 49e0531

Browse files
committed
updating docs
1 parent 8a29be5 commit 49e0531

File tree

3 files changed

+29
-209
lines changed

3 files changed

+29
-209
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -385,19 +385,19 @@ If you do a deep copy of obj, it should still give you the same hash:
385385
34150898645750099477987229399128149852
386386
```
387387

388-
Note that by default DeepHash will ignore string type differences. So if your strings were bytes, you would still get the same hash:
388+
Note that by default DeepHash will include string type differences. So if your strings were bytes:
389389

390390
```py
391391
>>> obj3 = {1: 2, b'a': b'b'}
392392
>>> DeepHash(obj3)[obj3]
393-
34150898645750099477987229399128149852
393+
64067525765846024488103933101621212760
394394
```
395395

396-
But if you want a different hash if string types are different, set ignore_string_type_changes to False:
396+
But if you want the same hash if string types are different, set ignore_string_type_changes to True:
397397

398398
```py
399-
>>> DeepHash(obj3, ignore_string_type_changes=False)[obj3]
400-
64067525765846024488103933101621212760
399+
>>> DeepHash(obj3, ignore_string_type_changes=True)[obj3]
400+
34150898645750099477987229399128149852
401401
```
402402

403403
# Using DeepDiff in unit tests

deepdiff/diff_doc.rst

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ exclude_paths: list, default = None
4646
exclude_regex_paths: list, default = None
4747
List of string regex paths or compiled regex paths objects to exclude from the report. If only one item, you can pass it as a string or regex compiled object.
4848

49-
exclude_types: list, default = None
50-
List of object types to exclude from the report.
5149

5250
hasher: default = DeepHash.murmur3_128bit
5351
Hash function to be used. If you don't want Murmur3, you can use Python's built-in hash function
@@ -59,13 +57,17 @@ view: string, default = text
5957
The new view is called the tree view which allows you to traverse through
6058
the tree of changed items.
6159

60+
exclude_types: list, default = None
61+
List of object types to exclude from the report.
62+
6263
ignore_string_type_changes: Boolean, default = False
6364
Whether to ignore string type changes or not. For example b"Hello" vs. "Hello" are considered the same if ignore_string_type_changes is set to True.
6465

6566
ignore_numeric_type_changes: Boolean, default = False
6667
Whether to ignore numeric type changes or not. For example 10 vs. 10.0 are considered the same if ignore_numeric_type_changes is set to True.
6768

68-
ignore_type_in_groups: Tuple or List of Tuples, default=None ignores types when t1 and t2 are both within the same type group.
69+
ignore_type_in_groups: Tuple or List of Tuples, default = None
70+
ignores types when t1 and t2 are both within the same type group.
6971

7072
**Returns**
7173

@@ -308,6 +310,17 @@ And if you don't care about the value of items that have changed type, please se
308310
{ 'type_changes': { 'root[2]': { 'new_type': <class 'str'>,
309311
'old_type': <class 'int'>}}}
310312

313+
314+
Exclude types
315+
316+
Exclude certain types from comparison:
317+
>>> l1 = logging.getLogger("test")
318+
>>> l2 = logging.getLogger("test2")
319+
>>> t1 = {"log": l1, 2: 1337}
320+
>>> t2 = {"log": l2, 2: 1337}
321+
>>> print(DeepDiff(t1, t2, exclude_types={logging.Logger}))
322+
{}
323+
311324
ignore_type_in_groups
312325

313326
Ignore type changes between members of groups of types. For example if you want to ignore type changes between float and decimals etc. Note that this is a more granular feature. Most of the times the shortcuts provided to you are enough.
@@ -316,7 +329,7 @@ The shortcuts are ignore_string_type_changes which by default is False and ignor
316329
For example lets say you have specifically str and byte datatypes to be ignored for type changes. Then you have a couple of options:
317330

318331
1. Set ignore_string_type_changes=True which is the default.
319-
2. Set ignore_type_in_groups=[(str, bytes)]. Here you are saying if we detect one type to be str and the other one bytes, do not report them as type change. It is exactly as passing ignore_type_in_groups=[DeepDiff.strings] or ignore_type_in_groups=DeepDiff.strings .
332+
2. Or set ignore_type_in_groups=[(str, bytes)]. Here you are saying if we detect one type to be str and the other one bytes, do not report them as type change. It is exactly as passing ignore_type_in_groups=[DeepDiff.strings] or ignore_type_in_groups=DeepDiff.strings .
320333

321334
Now what if you want also typeA and typeB to be ignored when comparing agains each other?
322335

@@ -651,17 +664,6 @@ Approximate float comparison (Significant digits after the point) (Tree View):
651664
>>> ddiff
652665
{'values_changed': {<root t1:1.23e+20, t2:1.24e+20>}}
653666

654-
655-
**Exclude types**
656-
657-
Exclude certain types from comparison:
658-
>>> l1 = logging.getLogger("test")
659-
>>> l2 = logging.getLogger("test2")
660-
>>> t1 = {"log": l1, 2: 1337}
661-
>>> t2 = {"log": l2, 2: 1337}
662-
>>> print(DeepDiff(t1, t2, exclude_types={logging.Logger}))
663-
{}
664-
665667
**Exclude paths**
666668

667669
Exclude part of your object tree from comparison

docs/index.rst

Lines changed: 7 additions & 189 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,9 @@ Importing
3535
>>> from deepdiff import DeepHash # For hashing objects based on their contents
3636
3737
********
38-
Features
38+
DeepDiff
3939
********
4040

41-
Parameters
42-
~~~~~~~~~~
43-
44-
- t1 (the first object)
45-
- t2 (the second object)
46-
- `ignore\_order`_
47-
- `report\_repetition`_
48-
- `exclude\_types\_or\_paths`_
49-
- `significant\_digits`_
50-
- `views`_
51-
5241
Supported data types
5342
~~~~~~~~~~~~~~~~~~~~
5443

@@ -74,34 +63,6 @@ List difference ignoring order or duplicates
7463
>>> print (ddiff)
7564
{}
7665
77-
Report repetitions
78-
~~~~~~~~~~~~~~~~~~
79-
80-
This flag ONLY works when ignoring order is enabled.
81-
82-
.. code:: python
83-
84-
t1 = [1, 3, 1, 4]
85-
t2 = [4, 4, 1]
86-
ddiff = DeepDiff(t1, t2, ignore_order=True, report_repetition=True)
87-
print(ddiff)
88-
89-
which will print you:
90-
91-
.. code:: python
92-
93-
{'iterable_item_removed': {'root[1]': 3},
94-
'repetition_change': {'root[0]': {'old_repeat': 2,
95-
'old_indexes': [0, 2],
96-
'new_indexes': [2],
97-
'value': 1,
98-
'new_repeat': 1},
99-
'root[3]': {'old_repeat': 1,
100-
'old_indexes': [3],
101-
'new_indexes': [0, 1],
102-
'value': 4,
103-
'new_repeat': 2}}}
104-
10566
Exclude types or paths
10667
~~~~~~~~~~~~~~~~~~~~~~
10768

@@ -117,16 +78,6 @@ Exclude certain types from comparison
11778
>>> print(DeepDiff(t1, t2, exclude_types={logging.Logger}))
11879
{}
11980
120-
Exclude part of your object tree from comparison
121-
------------------------------------------------
122-
123-
.. code:: python
124-
125-
>>> t1 = {"for life": "vegan", "ingredients": ["no meat", "no eggs", "no dairy"]}
126-
>>> t2 = {"for life": "vegan", "ingredients": ["veggies", "tofu", "soy sauce"]}
127-
>>> print (DeepDiff(t1, t2, exclude_paths={"root['ingredients']"}))
128-
{}
129-
13081
Significant Digits
13182
~~~~~~~~~~~~~~~~~~
13283

@@ -143,149 +94,23 @@ X=significant\_digits
14394
>>> DeepDiff(t1, t2, significant_digits=1)
14495
{'values_changed': {'root': {'old_value': Decimal('1.52'), 'new_value': Decimal('1.57')}}}
14596
146-
Approximate float comparison:
147-
-----------------------------
148-
149-
.. code:: python
150-
151-
>>> t1 = [ 1.1129, 1.3359 ]
152-
>>> t2 = [ 1.113, 1.3362 ]
153-
>>> pprint(DeepDiff(t1, t2, significant_digits=3))
154-
{}
155-
>>> pprint(DeepDiff(t1, t2))
156-
{'values_changed': {'root[0]': {'new_value': 1.113, 'old_value': 1.1129},
157-
'root[1]': {'new_value': 1.3362, 'old_value': 1.3359}}}
158-
>>> pprint(DeepDiff(1.23*10**20, 1.24*10**20, significant_digits=1))
159-
{'values_changed': {'root': {'new_value': 1.24e+20, 'old_value': 1.23e+20}}}
160-
161-
162-
Views
163-
~~~~~
164-
165-
Text View (default)
166-
-------------------
167-
168-
Text view is the original and currently the default view of DeepDiff.
169-
170-
It is called text view because the results contain texts that represent the path to the data:
171-
172-
Example of using the text view.
173-
>>> from deepdiff import DeepDiff
174-
>>> t1 = {1:1, 3:3, 4:4}
175-
>>> t2 = {1:1, 3:3, 5:5, 6:6}
176-
>>> ddiff = DeepDiff(t1, t2)
177-
>>> print(ddiff)
178-
{'dictionary_item_added': {'root[5]', 'root[6]'}, 'dictionary_item_removed': {'root[4]'}}
179-
180-
So for example ddiff['dictionary_item_removed'] is a set if strings thus this is called the text view.
181-
182-
.. seealso::
183-
The following examples are using the *default text view.*
184-
The Tree View is introduced in DeepDiff v3 and provides traversing capabilities through your diffed data and more!
185-
Read more about the Tree View at :doc:`/diff`
186-
187-
Tree View (new)
188-
---------------
189-
190-
Starting the version v3 You can choose the view into the deepdiff results.
191-
The tree view provides you with tree objects that you can traverse through to find
192-
the parents of the objects that are diffed and the actual objects that are being diffed.
193-
This view is very useful when dealing with nested objects.
194-
Note that tree view always returns results in the form of Python sets.
195-
196-
You can traverse through the tree elements!
197-
198-
.. note::
199-
The Tree view is just a different representation of the diffed data.
200-
Behind the scene, DeepDiff creates the tree view first and then converts it to textual representation for the text view.
201-
202-
.. code:: text
203-
204-
+---------------------------------------------------------------+
205-
| |
206-
| parent(t1) parent node parent(t2) |
207-
| + ^ + |
208-
+------|--------------------------|---------------------|-------+
209-
| | | up |
210-
| Child | | | ChildRelationship
211-
| Relationship | | |
212-
| down | | |
213-
+------|----------------------|-------------------------|-------+
214-
| v v v |
215-
| child(t1) child node child(t2) |
216-
| |
217-
+---------------------------------------------------------------+
218-
219-
220-
The tree view allows you to have more than mere textual representaion of the diffed objects.
221-
It gives you the actual objects (t1, t2) throughout the tree of parents and children.
222-
223-
:Example:
224-
225-
.. code:: python
226-
227-
>>> t1 = {1:1, 2:2, 3:3}
228-
>>> t2 = {1:1, 2:4, 3:3}
229-
>>> ddiff_verbose0 = DeepDiff(t1, t2, verbose_level=0, view='tree')
230-
>>> ddiff_verbose0
231-
{'values_changed': {<root[2]>}}
232-
>>>
233-
>>> ddiff_verbose1 = DeepDiff(t1, t2, verbose_level=1, view='tree')
234-
>>> ddiff_verbose1
235-
{'values_changed': {<root[2] t1:2, t2:4>}}
236-
>>> set_of_values_changed = ddiff_verbose1['values_changed']
237-
>>> # since set_of_values_changed includes only one item in a set
238-
>>> # in order to get that one item we can:
239-
>>> (changed,) = set_of_values_changed
240-
>>> changed # Another way to get this is to do: changed=list(set_of_values_changed)[0]
241-
<root[2] t1:2, t2:4>
242-
>>> changed.t1
243-
2
244-
>>> changed.t2
245-
4
246-
>>> # You can traverse through the tree, get to the parents!
247-
>>> changed.up
248-
<root t1:{1: 1, 2: 2,...}, t2:{1: 1, 2: 4,...}>
249-
250-
.. seealso::
251-
Read more about the Tree View at :doc:`/diff`
252-
253-
254-
Verbose Level
255-
~~~~~~~~~~~~~
256-
257-
Verbose level by default is 1. The possible values are 0, 1 and 2.
258-
259-
- verbose_level 0: won’t report values when type changed.
260-
- verbose_level 1: default
261-
- verbose_level 2: will report values when custom objects or
262-
dictionaries have items added or removed.
263-
264-
.. seealso::
265-
Read more about the verbosity at :doc:`/diff`
266-
26797
26898
Serialization
26999
~~~~~~~~~~~~~
270100

271-
DeepDiff uses jsonpickle in order to serialize and deserialize its results into json. This works for both tree view and text view.
272-
273-
:Serialize and then deserialize back to deepdiff:
101+
:Serialize to json:
274102

275103
.. code:: python
276104
277105
>>> t1 = {1: 1, 2: 2, 3: 3}
278106
>>> t2 = {1: 1, 2: "2", 3: 3}
279107
>>> ddiff = DeepDiff(t1, t2)
280-
>>> jsoned = ddiff.json
108+
>>> jsoned = ddiff.to_json()
281109
>>> jsoned
282-
'{"type_changes": {"root[2]": {"py/object": "deepdiff.helper.RemapDict", "new_type": {"py/type": "__builtin__.str"}, "new_value": "2", "old_type": {"py/type": "__builtin__.int"}, "old_value": 2}}}'
283-
>>> ddiff_new = DeepDiff.from_json(jsoned)
284-
>>> ddiff == ddiff_new
285-
True
110+
'{"type_changes": {"root[2]": {"new_type": "str", "new_value": "2", "old_type": "int", "old_value": 2}}}'
286111
287112
288-
Read more in
113+
And many more features! Read more in
289114

290115
:doc:`/diff`
291116

@@ -373,7 +198,7 @@ But with DeepHash:
373198
>>> from deepdiff import DeepHash
374199
>>> obj = {1: 2, 'a': 'b'}
375200
>>> DeepHash(obj)
376-
{4355639248: (2468916477072481777, 512283587789292749), 4355639280: (-3578777349255665377, -6377555218122431491), 4358636128: (-8839064797231613815, -1822486391929534118), 4358009664: (8833996863197925870, -419376694314494743), 4357467952: (3415089864575009947, 7987229399128149852)}
201+
{1: 2468916477072481777512283587789292749, 2: -35787773492556653776377555218122431491, ...}
377202
378203
So what is exactly the hash of obj in this case?
379204
DeepHash is calculating the hash of the obj and any other object that obj contains.
@@ -384,19 +209,12 @@ In order to get the hash of obj itself, you need to use the object (or the id of
384209
385210
>>> hashes = DeepHash(obj)
386211
>>> hashes[obj]
387-
(3415089864575009947, 7987229399128149852)
212+
34150898645750099477987229399128149852
388213
389214
Read more in the Deep Hash reference:
390215

391216
:doc:`/deephash`
392217

393-
.. _ignore\_order: #ignore-order
394-
.. _report\_repetition: #report-repetitions
395-
.. _verbose\_level: #verbose-level
396-
.. _exclude\_types\_or\_paths: #exclude-types-or-paths
397-
.. _significant\_digits: #significant-digits
398-
.. _views: #views
399-
400218

401219
References
402220
==========

0 commit comments

Comments
 (0)