Skip to content

Commit f129582

Browse files
authored
Update ignore_types_or_values.rst
1 parent 833a8d0 commit f129582

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

docs/ignore_types_or_values.rst

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,30 @@ Ignore Numeric Type Changes
6565
ignore_numeric_type_changes: Boolean, default = False
6666
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.
6767

68-
Example
68+
Example with Decimal
6969
>>> from decimal import Decimal
7070
>>> from deepdiff import DeepDiff
71-
>>>
71+
>>>
7272
>>> t1 = Decimal('10.01')
7373
>>> t2 = 10.01
74-
>>>
74+
>>>
7575
>>> DeepDiff(t1, t2)
7676
{'type_changes': {'root': {'old_type': <class 'decimal.Decimal'>, 'new_type': <class 'float'>, 'old_value': Decimal('10.01'), 'new_value': 10.01}}}
7777
>>> DeepDiff(t1, t2, ignore_numeric_type_changes=True)
7878
{}
7979

80+
Example with Fraction
81+
>>> from fractions import Fraction
82+
>>> from deepdiff import DeepDiff
83+
>>>
84+
>>> t1 = Fraction(1, 2)
85+
>>> t2 = 0.5
86+
>>>
87+
>>> DeepDiff(t1, t2)
88+
{'type_changes': {'root': {'old_type': <class 'fractions.Fraction'>, 'new_type': <class 'float'>, 'old_value': Fraction(1, 2), 'new_value': 0.5}}}
89+
>>> DeepDiff(t1, t2, ignore_numeric_type_changes=True)
90+
{}
91+
8092
Note that this parameter only works for comparing numbers with numbers. If you compare a number to a string value of the number, this parameter does not solver your problem:
8193

8294
Example:

0 commit comments

Comments
 (0)