You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+5-1Lines changed: 5 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -48,7 +48,9 @@ DeepDiff gets the difference of 2 objects.
48
48
> - Please take a look at the [DeepDiff docs](deepdiff/diff_doc.rst)
49
49
> - The full documentation can be found on <https://deepdiff.readthedocs.io>
50
50
51
-
## Examples
51
+
## A few Examples
52
+
53
+
> Note: This is just a brief overview of what DeepDiff can do. Please visit <https://deepdiff.readthedocs.io> for full documentation.
52
54
53
55
### List difference ignoring order or duplicates
54
56
@@ -415,6 +417,8 @@ And then running
415
417
416
418
# ChangeLog
417
419
420
+
- v4-0-4: Adding ignore_string_case and ignore_type_subclasses
421
+
- v4-0-3: Adding versionbump tool for release
418
422
- v4-0-2: Fixing installation issue where rst files are missing.
419
423
- v4-0-1: Fixing installation Tarball missing requirements.txt . DeepDiff v4+ should not show up as pip installable for Py2. Making Murmur3 installation optional.
420
424
- v4-0-0: Ending Python 2 support, Adding more functionalities and documentation for DeepHash. Switching to Pytest for testing. Switching to Murmur3 128bit for hashing. Fixing classes which inherit from classes with slots didn't have all of their slots compared. Renaming ContentHash to DeepHash. Adding exclude by path and regex path to DeepHash. Adding ignore_type_in_groups. Adding match_string to DeepSearch. Adding Timedelta object diffing.
Copy file name to clipboardExpand all lines: deepdiff/deephash_doc.rst
+67-14Lines changed: 67 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,7 @@ At the core of it, DeepHash is a deterministic serialization of your object into
10
10
can be passed to a hash function. By default it uses Murmur 3 128 bit hash function which is a
11
11
fast, non-cryptographic hashing function. You have the option to pass any another hashing function to be used instead.
12
12
13
-
If it can't find Murmur3 package (mmh3) installed, it uses Python's built-in SHA256 for hashing which is considerably slower than Murmur3. So it is advised that you install Murmur3 by running `pip install mmh3`
13
+
If it can't find Murmur3 package (mmh3) installed, it uses Python's built-in SHA256 for hashing which is considerably slower than Murmur3. So it is advised that you install Murmur3 by running `pip install 'deepdiff[murmur]`
14
14
15
15
**Import**
16
16
>>> from deepdiff import DeepHash
@@ -138,6 +138,15 @@ ignore_type_in_groups example with custom objects:
138
138
>>> d1[burrito] == d2[taco]
139
139
True
140
140
141
+
142
+
ignore_type_subclasses
143
+
Use ignore_type_subclasses=True so when ignoring type (class), the subclasses of that class are ignored too.
144
+
145
+
146
+
ignore_string_case
147
+
Whether to be case-sensitive or not when comparing strings. By settings ignore_string_case=False, strings will be compared case-insensitively.
148
+
149
+
141
150
**Returns**
142
151
A dictionary of {item: item hash}.
143
152
If your object is nested, it will build hashes of all the objects it contains too.
DeepHash is calculating the hash of the obj and any other object that obj contains.
166
-
The output of DeepHash is a dictionary of object IDs to their hashes.
167
-
In order to get the hash of obj itself, you need to use the object (or the id of object) to get its hash:
173
+
So what is exactly the hash of obj in this case?
174
+
DeepHash is calculating the hash of the obj and any other object that obj contains.
175
+
The output of DeepHash is a dictionary of object IDs to their hashes.
176
+
In order to get the hash of obj itself, you need to use the object (or the id of object) to get its hash:
168
177
>>> hashes = DeepHash(obj)
169
178
>>> hashes[obj]
170
179
34150898645750099477987229399128149852
171
180
172
-
Which you can write as:
181
+
Which you can write as:
173
182
>>> hashes = DeepHash(obj)[obj]
174
183
175
-
At first it might seem weird why DeepHash(obj)[obj] but remember that DeepHash(obj) is a dictionary of hashes of all other objects that obj contains too.
184
+
At first it might seem weird why DeepHash(obj)[obj] but remember that DeepHash(obj) is a dictionary of hashes of all other objects that obj contains too.
176
185
177
-
The result hash is 34150898645750099477987229399128149852 which is generated by
178
-
Murmur 3 128bit hashing algorithm. If you prefer to use another hashing algorithm, you can pass it using the hasher parameter. Read more about Murmur3 here: https://en.wikipedia.org/wiki/MurmurHash
186
+
The result hash is 34150898645750099477987229399128149852 which is generated by
187
+
Murmur 3 128bit hashing algorithm. If you prefer to use another hashing algorithm, you can pass it using the hasher parameter. Read more about Murmur3 here: https://en.wikipedia.org/wiki/MurmurHash
179
188
180
-
If you do a deep copy of obj, it should still give you the same hash:
189
+
If you do a deep copy of obj, it should still give you the same hash:
181
190
>>> from copy import deepcopy
182
191
>>> obj2 = deepcopy(obj)
183
192
>>> DeepHash(obj2)[obj2]
184
193
34150898645750099477987229399128149852
185
194
186
-
Note that by default DeepHash will include string type differences. So if your strings were bytes:
195
+
Note that by default DeepHash will include string type differences. So if your strings were bytes:
187
196
>>> obj3 = {1: 2, b'a': b'b'}
188
197
>>> DeepHash(obj3)[obj3]
189
198
64067525765846024488103933101621212760
190
199
191
-
But if you want the same hash if string types are different, set ignore_string_type_changes to True:
200
+
But if you want the same hash if string types are different, set ignore_string_type_changes to True:
ignore_type_in_groups: Tuple or List of Tuples, default = None
70
70
ignores types when t1 and t2 are both within the same type group.
71
71
72
+
ignore_type_subclasses: Boolean, default = False
73
+
ignore type (class) changes when dealing with the subclasses of classes that were marked to be ignored.
74
+
75
+
ignore_string_case: Boolean, default = False
76
+
Whether to be case-sensitive or not when comparing strings. By settings ignore_string_case=False, strings will be compared case-insensitively.
77
+
72
78
**Returns**
73
79
74
80
A DeepDiff object that has already calculated the difference of the 2 items.
@@ -322,31 +328,27 @@ Exclude certain types from comparison:
322
328
{}
323
329
324
330
ignore_type_in_groups
331
+
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.
332
+
The shortcuts are ignore_string_type_changes which by default is False and ignore_numeric_type_changes which is by default False. You can read more about those shortcuts in this page. ignore_type_in_groups gives you more control compared to the shortcuts.
325
333
326
-
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.
327
-
The shortcuts are ignore_string_type_changes which by default is False and ignore_numeric_type_changes which is by default False. You can read more about those shortcuts in this page. ignore_type_in_groups gives you more control compared to the shortcuts.
334
+
For example lets say you have specifically str and byte datatypes to be ignored for type changes. Then you have a couple of options:
328
335
329
-
For example lets say you have specifically str and byte datatypes to be ignored for type changes. Then you have a couple of options:
336
+
1. Set ignore_string_type_changes=True.
337
+
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 .
330
338
331
-
1. Set ignore_string_type_changes=True.
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 .
339
+
Now what if you want also typeA and typeB to be ignored when comparing agains each other?
333
340
334
-
Now what if you want also typeA and typeB to be ignored when comparing agains each other?
Ignore Type Number - Dictionary that contains float and integer:
350
+
ignore_numeric_type_changes Default: False
351
+
Ignore Type Number - Dictionary that contains float and integer
350
352
>>> from deepdiff import DeepDiff
351
353
>>> from pprint import pprint
352
354
>>> t1 = {1: 1, 2: 2.22}
@@ -361,7 +363,7 @@ Ignore Type Number - Dictionary that contains float and integer:
361
363
>>> pprint(ddiff, indent=2)
362
364
{}
363
365
364
-
Ignore Type Number - List that contains float and integer:
366
+
Ignore Type Number - List that contains float and integer
365
367
>>> from deepdiff import DeepDiff
366
368
>>> from pprint import pprint
367
369
>>> t1 = [1, 2, 3]
@@ -384,7 +386,7 @@ Ignore Type Number - List that contains float and integer:
384
386
>>> pprint(ddiff, indent=2)
385
387
{}
386
388
387
-
You can pass a list of tuples or list of lists if you have various type groups. When t1 and t2 both fall under one of these type groups, the type change will be ignored. DeepDiff already comes with 2 groups: DeepDiff.strings and DeepDiff.numbers . If you want to pass both:
389
+
You can pass a list of tuples or list of lists if you have various type groups. When t1 and t2 both fall under one of these type groups, the type change will be ignored. DeepDiff already comes with 2 groups: DeepDiff.strings and DeepDiff.numbers . If you want to pass both:
Copy file name to clipboardExpand all lines: docs/index.rst
+4-2Lines changed: 4 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,7 +27,7 @@ Install from PyPi::
27
27
28
28
DeepDiff prefers to use Murmur3 for hashing. However you have to manually install Murmur3 by running::
29
29
30
-
pip install mmh3
30
+
pip install 'deepdiff[murmur]'
31
31
32
32
Otherwise DeepDiff will be using SHA256 for hashing which is a cryptographic hash and is considerably slower.
33
33
@@ -51,7 +51,7 @@ Read The DeepDiff details in:
51
51
52
52
:doc:`/diff`
53
53
54
-
Short introduction::
54
+
Short introduction
55
55
56
56
Supported data types
57
57
~~~~~~~~~~~~~~~~~~~~
@@ -281,6 +281,8 @@ Indices and tables
281
281
Changelog
282
282
=========
283
283
284
+
- v4-0-4: Adding ignore_string_case and ignore_type_subclasses
285
+
- v4-0-3: Adding versionbump tool for release
284
286
- v4-0-2: Fixing installation issue where rst files are missing.
285
287
- v4-0-1: Fixing installation Tarball missing requirements.txt . DeepDiff v4+ should not show up as pip installable for Py2. Making Murmur3 installation optional.
286
288
- v4-0-0: Ending Python 2 support, Adding more functionalities and documentation for DeepHash. Switching to Pytest for testing. Switching to Murmur3 128bit for hashing. Fixing classes which inherit from classes with slots didn't have all of their slots compared. Renaming ContentHash to DeepHash. Adding exclude by path and regex path to DeepHash. Adding ignore_type_in_groups. Adding match_string to DeepSearch. Adding Timedelta object diffing.
0 commit comments