Skip to content

Commit 8a7a004

Browse files
committed
adding docs
1 parent 3228f4b commit 8a7a004

File tree

5 files changed

+86
-1
lines changed

5 files changed

+86
-1
lines changed

deepdiff/diff.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def __init__(self,
158158
report_repetition: bool=False,
159159
significant_digits: Optional[int]=None,
160160
use_log_scale: bool=False,
161-
log_scale_similarity_threshold: int=0.1,
161+
log_scale_similarity_threshold: float=0.1,
162162
threshold_to_diff_deeper: float = 0.33,
163163
truncate_datetime: Optional[str]=None,
164164
use_enum_value: bool=False,

docs/diff_doc.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ log_frequency_in_sec: Integer, default = 0
151151
If you set it to 20, it will log every 20 seconds. This is useful only when running DeepDiff
152152
on massive objects that will take a while to run. If you are only dealing with small objects, keep it at 0 to disable progress logging.
153153

154+
log_scale_similarity_threshold: float, default = 0.1
155+
:ref:`use_log_scale_label` along with :ref:`log_scale_similarity_threshold_label` can be used to ignore small changes in numbers by comparing their differences in logarithmic space. This is different than ignoring the difference based on significant digits.
156+
154157
max_passes: Integer, default = 10000000
155158
:ref:`max_passes_label` defined the maximum number of passes to run on objects to pin point what exactly is different. This is only used when ignore_order=True. A new pass is started each time 2 iterables are compared in a way that every single item that is different from the first one is compared to every single item that is different in the second iterable.
156159

@@ -179,6 +182,15 @@ significant_digits : int >= 0, default=None
179182
truncate_datetime: string, default = None
180183
:ref:`truncate_datetime_label` can take value one of 'second', 'minute', 'hour', 'day' and truncate with this value datetime objects before hashing it
181184

185+
threshold_to_diff_deeper: float, default = 0.33
186+
:ref:`threshold_to_diff_deeper_label` is a number between 0 and 1. When comparing dictionaries that have a small intersection of keys, we will report the dictionary as a new_value instead of reporting individual keys changed. If you set it to zero, you get the same results as DeepDiff 7.0.1 and earlier, which means this feature is disabled. The new default is 0.33 which means if less that one third of keys between dictionaries intersect, report it as a new object.
187+
188+
use_enum_value: Boolean, default=False
189+
:ref:`use_enum_value_label` makes it so when diffing enum, we use the enum's value. It makes it so comparing an enum to a string or any other value is not reported as a type change.
190+
191+
use_log_scale: Boolean, default=False
192+
:ref:`use_log_scale_label` along with :ref:`log_scale_similarity_threshold_label` can be used to ignore small changes in numbers by comparing their differences in logarithmic space. This is different than ignoring the difference based on significant digits.
193+
182194
verbose_level: 2 >= int >= 0, default = 1
183195
Higher verbose level shows you more details.
184196
For example verbose level 1 shows what dictionary item are added or removed.

docs/ignore_types_or_values.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,4 +362,26 @@ truncate_datetime: string, default = None
362362
{}
363363

364364

365+
.. _use_enum_value_label:
366+
367+
Use Enum Value
368+
--------------
369+
370+
use_enum_value: Boolean, default=False
371+
Makes it so when diffing enum, we use the enum's value. It makes it so comparing an enum to a string or any other value is not reported as a type change.
372+
373+
>>> from enum import Enum
374+
>>> from deepdiff import DeepDiff
375+
376+
>>>
377+
>>> class MyEnum2(str, Enum):
378+
... book = "book"
379+
... cake = "cake"
380+
...
381+
>>> DeepDiff("book", MyEnum2.book)
382+
{'type_changes': {'root': {'old_type': <class 'str'>, 'new_type': <enum 'MyEnum2'>, 'old_value': 'book', 'new_value': <MyEnum2.book: 'book'>}}}
383+
>>> DeepDiff("book", MyEnum2.book, use_enum_value=True)
384+
{}
385+
386+
365387
Back to :doc:`/index`

docs/numbers.rst

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,39 @@ Example:
142142
math_epsilon cannot currently handle the hashing of values, which is done when :ref:`ignore_order_label` is True.
143143

144144

145+
.. _use_log_scale_label:
146+
147+
Use Log Scale
148+
-------------
149+
150+
use_log_scale: Boolean, default=False
151+
use_log_scale along with :ref:`log_scale_similarity_threshold_label` can be used to ignore small changes in numbers by comparing their differences in logarithmic space. This is different than ignoring the difference based on significant digits.
152+
153+
154+
>>> from deepdiff import DeepDiff
155+
156+
>>> t1 = {'foo': 110, 'bar': 306}
157+
>>> t2 = {'foo': 140, 'bar': 298}
158+
>>>
159+
>>> DeepDiff(t1, t2)
160+
{'values_changed': {"root['foo']": {'new_value': 140, 'old_value': 110}, "root['bar']": {'new_value': 298, 'old_value': 306}}}
161+
>>> DeepDiff(t1, t2, use_log_scale=True, log_scale_similarity_threshold=0.01)
162+
{'values_changed': {"root['foo']": {'new_value': 140, 'old_value': 110}, "root['bar']": {'new_value': 298, 'old_value': 306}}}
163+
>>> DeepDiff(t1, t2, use_log_scale=True, log_scale_similarity_threshold=0.1)
164+
{'values_changed': {"root['foo']": {'new_value': 140, 'old_value': 110}}}
165+
>>> DeepDiff(t1, t2, use_log_scale=True, log_scale_similarity_threshold=0.3)
166+
{
167+
168+
169+
.. _log_scale_similarity_threshold_label:
170+
171+
Log Scale Similarity Threshold
172+
------------
173+
174+
log_scale_similarity_threshold: float, default = 0.1
175+
:ref:`use_log_scale_label` along with log_scale_similarity_threshold can be used to ignore small changes in numbers by comparing their differences in logarithmic space. This is different than ignoring the difference based on significant digits. See above example.
176+
177+
145178
Performance Improvement of Numbers diffing
146179
------------------------------------------
147180

docs/optimizations.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,5 +266,23 @@ zip_ordered_iterables: Boolean, default = False
266266
'root[3]': {'new_value': 'd', 'old_value': 'e'}}}
267267

268268

269+
.. _threshold_to_diff_deeper_label:
270+
271+
Threshold To Diff Deeper
272+
------------------------
273+
274+
threshold_to_diff_deeper: float, default = 0.33
275+
threshold_to_diff_deeper is a number between 0 and 1. When comparing dictionaries that have a small intersection of keys, we will report the dictionary as a new_value instead of reporting individual keys changed. If you set it to zero, you get the same results as DeepDiff 7.0.1 and earlier, which means this feature is disabled. The new default is 0.33 which means if less that one third of keys between dictionaries intersect, report it as a new object.
276+
277+
278+
>>> from deepdiff import DeepDiff
279+
>>> t1 = {"veggie": "carrots"}
280+
>>> t2 = {"meat": "carrots"}
281+
>>>
282+
>>> DeepDiff(t1, t2, threshold_to_diff_deeper=0)
283+
{'dictionary_item_added': ["root['meat']"], 'dictionary_item_removed': ["root['veggie']"]}
284+
>>> DeepDiff(t1, t2, threshold_to_diff_deeper=0.33)
285+
{'values_changed': {'root': {'new_value': {'meat': 'carrots'}, 'old_value': {'veggie': 'carrots'}}}}
286+
269287

270288
Back to :doc:`/index`

0 commit comments

Comments
 (0)