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
To check against that the math core module provides the valuable isclose() function. It evaluates the being close of two numbers to each other, with reference to an epsilon (abs_tol). This is superior to the format function, as it evaluates the mathematical representation and not the string representation.
133
142
134
-
Example:
143
+
Example with Decimal:
135
144
>>> from decimal import Decimal
136
145
>>> d1 = {"a": Decimal("7.175")}
137
146
>>> d2 = {"a": Decimal("7.174")}
138
147
>>> DeepDiff(d1, d2, math_epsilon=0.01)
139
148
{}
140
149
150
+
Example with Fraction:
151
+
>>> from fractions import Fraction
152
+
>>> d1 = {"a": Fraction(7175, 1000)}
153
+
>>> d2 = {"a": Fraction(7174, 1000)}
154
+
>>> DeepDiff(d1, d2, math_epsilon=0.01)
155
+
{}
156
+
141
157
.. note::
142
158
math_epsilon cannot currently handle the hashing of values, which is done when :ref:`ignore_order_label` is True.
0 commit comments