Skip to content

Commit cecfa91

Browse files
committed
docs
1 parent 56b9bc2 commit cecfa91

File tree

7 files changed

+91
-115
lines changed

7 files changed

+91
-115
lines changed

AUTHORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,4 @@ Authors in order of the timeline of their contributions:
4343
- [SlavaSkvortsov](https://github.com/SlavaSkvortsov) for fixing unprocessed key error.
4444
- Håvard Thom [havardthom](https://github.com/havardthom) for adding UUID support.
4545
- Dhanvantari Tilak [Dhanvantari](https://github.com/Dhanvantari) for Bug-Fix: `TypeError in _get_numbers_distance() when ignore_order = True`.
46+
- Yael Mintz [yaelmi3](https://github.com/yaelmi3) for detailed pretty print when verbose_level=2.

README.md

Lines changed: 10 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -18,68 +18,23 @@ Tested on Python 3.6+ and PyPy3.
1818

1919
## What is new?
2020

21+
DeepDiff 5-8-0 includes bug fixes and improvements:
22+
23+
- Fixed the bug with delta randomly not producing the same results when `ignore_order=True` (https://github.com/seperman/deepdiff/issues/277)
24+
- Display detailed pretty when verbose by [Yael Mintz](https://github.com/yaelmi3)
25+
- Allow ordered-set version 4.1.x by [Tal Amuyal](https://github.com/TalAmuyal)
26+
- Removing extra logging when key is not found in DeepHash (https://github.com/seperman/deepdiff/issues/293)
27+
- Fixed error when comparing non-utf8 byte strings with ignore_order=True(https://github.com/seperman/deepdiff/issues/292)
28+
- Fixed Tests fail after 2022-05-14 (https://github.com/seperman/deepdiff/issues/255)
29+
- Fixed [TypeError is thrown when comparing bool and str](https://github.com/seperman/deepdiff/issues/275)
30+
2131
DeepDiff 5-7-0 includes bug fixes and improvements:
2232

2333
- https://github.com/seperman/deepdiff/pull/284 Bug-Fix: TypeError in _get_numbers_distance() when ignore_order = True by @Dhanvantari
2434
- https://github.com/seperman/deepdiff/pull/280 Add support for UUIDs by @havardthom
2535
- Major bug in delta when it comes to iterable items added or removed is investigated by @uwefladrich and resolved by @seperman
2636

2737

28-
DeepDiff 5-6-0 allows you to pass custom operators.
29-
30-
```python
31-
>>> from deepdiff import DeepDiff
32-
>>> from deepdiff.operator import BaseOperator
33-
>>> class CustomClass:
34-
... def __init__(self, d: dict, l: list):
35-
... self.dict = d
36-
... self.dict['list'] = l
37-
...
38-
>>>
39-
>>> custom1 = CustomClass(d=dict(a=1, b=2), l=[1, 2, 3])
40-
>>> custom2 = CustomClass(d=dict(c=3, d=4), l=[1, 2, 3, 2])
41-
>>> custom3 = CustomClass(d=dict(a=1, b=2), l=[1, 2, 3, 4])
42-
>>>
43-
>>>
44-
>>> class ListMatchOperator(BaseOperator):
45-
... def give_up_diffing(self, level, diff_instance):
46-
... if set(level.t1.dict['list']) == set(level.t2.dict['list']):
47-
... return True
48-
...
49-
>>>
50-
>>> DeepDiff(custom1, custom2, custom_operators=[
51-
... ListMatchOperator(types=[CustomClass])
52-
... ])
53-
{}
54-
>>>
55-
>>>
56-
>>> DeepDiff(custom2, custom3, custom_operators=[
57-
... ListMatchOperator(types=[CustomClass])
58-
... ])
59-
{'dictionary_item_added': [root.dict['a'], root.dict['b']], 'dictionary_item_removed': [root.dict['c'], root.dict['d']], 'values_changed': {"root.dict['list'][3]": {'new_value': 4, 'old_value': 2}}}
60-
>>>
61-
62-
```
63-
64-
**New in 5-6-0: Dynamic ignore order function**
65-
66-
Ignoring order when certain word in the path
67-
68-
```python
69-
>>> from deepdiff import DeepDiff
70-
>>> t1 = {'a': [1, 2], 'b': [3, 4]}
71-
>>> t2 = {'a': [2, 1], 'b': [4, 3]}
72-
>>> DeepDiff(t1, t2, ignore_order=True)
73-
{}
74-
>>> def ignore_order_func(level):
75-
... return 'a' in level.path()
76-
...
77-
>>> DeepDiff(t1, t2, ignore_order=True, ignore_order_func=ignore_order_func)
78-
{'values_changed': {"root['b'][0]": {'new_value': 4, 'old_value': 3}, "root['b'][1]": {'new_value': 3, 'old_value': 4}}}
79-
80-
```
81-
82-
8338
## Installation
8439

8540
### Install from PyPi:

docs/authors.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ Authors in order of the timeline of their contributions:
5555
- Håvard Thom `havardthom`_ for adding UUID support.
5656
- Dhanvantari Tilak `Dhanvantari`_ for Bug-Fix:
5757
``TypeError in _get_numbers_distance() when ignore_order = True``.
58+
- Yael Mintz `yaelmi3`_ for detailed pretty print when verbose_level=2.
5859

5960
.. _Sep Dehpour (Seperman): http://www.zepworks.com
6061
.. _Victor Hahn Castell: http://hahncastell.de
@@ -94,6 +95,8 @@ Authors in order of the timeline of their contributions:
9495
.. _SlavaSkvortsov: https://github.com/SlavaSkvortsov
9596
.. _havardthom: https://github.com/havardthom
9697
.. _Dhanvantari: https://github.com/Dhanvantari
98+
.. _yaelmi3: https://github.com/yaelmi3
99+
97100

98101
Thank you for contributing to DeepDiff!
99102

docs/diff.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,17 @@ DeepDiff
1414
:maxdepth: 3
1515

1616
basics
17-
view
17+
custom
18+
deep_distance
19+
exclude_paths
1820
ignore_order
1921
ignore_types_or_values
20-
exclude_paths
21-
deep_distance
2222
numbers
23-
serialization
2423
optimizations
24+
other
25+
serialization
2526
stats
26-
custom
2727
troubleshoot
28+
view
2829

2930
Back to :doc:`/index`

docs/diff_doc.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ custom_operators : BaseOperator subclasses, default = None
3737
:ref:`custom_operators_label` if you are considering whether they are fruits or not. In that case, you can pass a *custom_operators* for the job.
3838

3939
encodings: List, default = None
40-
Character encodings to iterate through when we convert bytes into strings. You may want to pass an explicit list of encodings in your objects if you start getting UnicodeDecodeError from DeepHash. Also check out ignore_encoding_errors if you can get away with ignoring these errors and don't want to bother with an explicit list of encodings but it will come at the price of slightly less accuracy of the final results. Example: encodings=["utf-8", "latin-1"]
40+
:ref:`encodings_label` Character encodings to iterate through when we convert bytes into strings. You may want to pass an explicit list of encodings in your objects if you start getting UnicodeDecodeError from DeepHash. Also check out :ref:`ignore_encoding_errors_label` if you can get away with ignoring these errors and don't want to bother with an explicit list of encodings but it will come at the price of slightly less accuracy of the final results. Example: encodings=["utf-8", "latin-1"]
4141

4242
exclude_paths: list, default = None
4343
:ref:`exclude_paths_label`
@@ -106,7 +106,7 @@ ignore_private_variables: Boolean, default = True
106106

107107

108108
ignore_encoding_errors: Boolean, default = False
109-
If you want to get away with UnicodeDecodeError without passing explicit character encodings, set this option to True. If you want to make sure the encoding is done properly, keep this as False and instead pass an explicit list of character encodings to be considered via the encodings parameter.
109+
:ref:`ignore_encoding_errors_label` If you want to get away with UnicodeDecodeError without passing explicit character encodings, set this option to True. If you want to make sure the encoding is done properly, keep this as False and instead pass an explicit list of character encodings to be considered via the :ref:`encodings_label` parameter.
110110

111111

112112
iterable_compare_func:

docs/index.rst

Lines changed: 14 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -31,66 +31,27 @@ The DeepDiff library includes the following modules:
3131
What is New
3232
***********
3333

34+
New In DeepDiff 5-8-0
35+
---------------------
36+
37+
DeepDiff 5-8-0 includes bug fixes and improvements:
38+
39+
- Fixed the bug with delta randomly not producing the same results when `ignore_order=True`
40+
- Display detailed pretty when verbose
41+
- Allow ordered-set version 4.1.x
42+
- Removing extra logging when key is not found in DeepHash
43+
- Fixed error when comparing non-utf8 byte strings with ignore_order=True
44+
- Fixed Tests fail after 2022-05-14
45+
- Fixed TypeError is thrown when comparing bool and str
46+
47+
3448
New In DeepDiff 5-7-0
3549
---------------------
3650

3751
- https://github.com/seperman/deepdiff/pull/284 Bug-Fix: TypeError in _get_numbers_distance() when ignore_order = True by @Dhanvantari
3852
- https://github.com/seperman/deepdiff/pull/280 Add support for UUIDs by @havardthom
3953
- Major bug in delta when it comes to iterable items added or removed is investigated by @uwefladrich and resolved by @seperman
4054

41-
New In DeepDiff 5-6-0
42-
---------------------
43-
44-
**Create custom operators!**
45-
46-
>>> from deepdiff import DeepDiff
47-
>>> from deepdiff.operator import BaseOperator
48-
>>> class CustomClass:
49-
... def __init__(self, d: dict, l: list):
50-
... self.dict = d
51-
... self.dict['list'] = l
52-
...
53-
>>>
54-
>>> custom1 = CustomClass(d=dict(a=1, b=2), l=[1, 2, 3])
55-
>>> custom2 = CustomClass(d=dict(c=3, d=4), l=[1, 2, 3, 2])
56-
>>> custom3 = CustomClass(d=dict(a=1, b=2), l=[1, 2, 3, 4])
57-
>>>
58-
>>>
59-
>>> class ListMatchOperator(BaseOperator):
60-
... def give_up_diffing(self, level, diff_instance):
61-
... if set(level.t1.dict['list']) == set(level.t2.dict['list']):
62-
... return True
63-
...
64-
>>>
65-
>>> DeepDiff(custom1, custom2, custom_operators=[
66-
... ListMatchOperator(types=[CustomClass])
67-
... ])
68-
{}
69-
>>>
70-
>>>
71-
>>> DeepDiff(custom2, custom3, custom_operators=[
72-
... ListMatchOperator(types=[CustomClass])
73-
... ])
74-
{'dictionary_item_added': [root.dict['a'], root.dict['b']], 'dictionary_item_removed': [root.dict['c'], root.dict['d']], 'values_changed': {"root.dict['list'][3]": {'new_value': 4, 'old_value': 2}}}
75-
>>>
76-
77-
78-
**Dynamic ignore order function**
79-
80-
Ignoring order when certain word in the path
81-
82-
>>> from deepdiff import DeepDiff
83-
>>> t1 = {'a': [1, 2], 'b': [3, 4]}
84-
>>> t2 = {'a': [2, 1], 'b': [4, 3]}
85-
>>> DeepDiff(t1, t2, ignore_order=True)
86-
{}
87-
>>> def ignore_order_func(level):
88-
... return 'a' in level.path()
89-
...
90-
>>> DeepDiff(t1, t2, ignore_order=True, ignore_order_func=ignore_order_func)
91-
{'values_changed': {"root['b'][0]": {'new_value': 4, 'old_value': 3}, "root['b'][1]": {'new_value': 3, 'old_value': 4}}}
92-
93-
9455
*********
9556
Tutorials
9657
*********

docs/other.rst

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
:doc:`/index`
2+
3+
Other Parameters
4+
================
5+
6+
7+
.. _encodings_label:
8+
9+
Encodings
10+
---------
11+
12+
significant_digits : int >= 0, default=None
13+
14+
Character encodings to iterate through when we convert bytes into strings. You may want to pass an explicit list of encodings in your objects if you start getting UnicodeDecodeError from DeepHash. Also check out :ref:`ignore_encoding_errors_label` if you can get away with ignoring these errors and don't want to bother with an explicit list of encodings but it will come at the price of slightly less accuracy of the final results. Example: encodings=["utf-8", "latin-1"]
15+
16+
The reason the decoding of bytes to string is needed is that when `ignore_order = True` we calculate the hash of the objects in order to facilitate in diffing them. In order to calculate the hash, we serialize all objects into strings. During the serialization we may encounter issues with character encodings.
17+
18+
**Examples:**
19+
20+
Comparing bytes that have non UTF-8 encoding:
21+
>>> from deepdiff import DeepDiff
22+
>>> item = b"\xbc cup of flour"
23+
>>> DeepDiff([b'foo'], [item], ignore_order=True)
24+
Traceback (most recent call last):
25+
raise UnicodeDecodeError(
26+
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xbc in position 0: Can not produce a hash for root: invalid start byte in 'p of flo...'. Please either pass ignore_encoding_errors=True or pass the encoding via encodings=['utf-8', '...'].
27+
28+
Let's try to pass both 'utf-8' and 'latin-1' as encodings to be tries:
29+
>>> DeepDiff([b'foo'], [item], encodings=['utf-8', 'latin-1'], ignore_order=True)
30+
{'values_changed': {'root[0]': {'new_value': b'\xbc cup of flour', 'old_value': b'foo'}}}
31+
32+
33+
.. _ignore_encoding_errors_label:
34+
35+
Ignore Encoding Errors
36+
----------------------
37+
38+
ignore_encoding_errors: Boolean, default = False
39+
40+
If you want to get away with UnicodeDecodeError without passing explicit character encodings, set this option to True. If you want to make sure the encoding is done properly, keep this as False and instead pass an explicit list of character encodings to be considered via the encodings parameter.
41+
42+
We can generally get the same results as above example if we just pass `ignore_encoding_errors=True`. However it comes at the cost of less accuracy of the results.
43+
>>> DeepDiff([b'foo'], [b"\xbc cup of flour"], ignore_encoding_errors=True, ignore_order=True)
44+
{'values_changed': {'root[0]': {'new_value': b'\xbc cup of flour', 'old_value': b'foo'}}}
45+
46+
For example if we replace `foo` with ` cup of flour`, we have bytes that are only different in the problematic character. Ignoring that character means DeepDiff will consider these 2 strings to be equal since their hash becomes the same. Note that we only hash items when `ignore_order=True`.
47+
>>> DeepDiff([b" cup of flour"], [b"\xbc cup of flour"], ignore_encoding_errors=True, ignore_order=True)
48+
{}
49+
50+
But if we had passed the proper encoding, it would have detected that these 2 bytes are different:
51+
>>> DeepDiff([b" cup of flour"], [b"\xbc cup of flour"], encodings=['latin-1'], ignore_order=True)
52+
{'values_changed': {'root[0]': {'new_value': b'\xbc cup of flour', 'old_value': b' cup of flour'}}}
53+
54+
55+
Back to :doc:`/index`

0 commit comments

Comments
 (0)