Comparing Python dicts with floating point values included
<p>I want to compare a pair of dictionaries and using 'fuzzy' floating point comparison or better yet use <code>numpy.allclose()</code> to do so.  However, using the default <code>==</code> or <code>!=</code> in Python for dicts doesn't do this.</p>

<p>I was wondering if there was a way to change the floating point comparison operation (probably using a context manager for safe cleanup).</p>

<p>I believe an example will help here.  I have a deeply nested dict that contains all sorts of values.  Some of these values are floating point values.  I know there are tons of pitfalls for 'comparing' floating point values, etc.</p>

<pre><code>d1 = {'a': {'b': 1.123456}}
d2 = {'a': {'b': 1.1234578}}
</code></pre>

<p>I would like to use <code>!=</code> to compare these two dicts and have it return <code>True</code> if the only differences are floating point numbers within a certain range.  For example, do not count the values different if the are <strong>close</strong> (not sure the precision I want yet).</p>

<p>I suppose I could recursively go through the dicts myself and manually just use <code>numpy.allclose()</code> for floating point values and fall back to the normal equality testing for all other types, etc.  However, this is a bit tricky and error prone.  I do think this would be an acceptable solution, and I'd love to see one like it.  Hopefully there is something more elegant though.</p>

<p>The elegant solution in my head would look something like the following.  However, I don't know if anything like this is even possible:</p>

<pre><code>with hacked_float_compare:
    result = d1 != d2
</code></pre>

<p>Thus, inside this context manager I would be replacing the floating point comparison (just for standard <code>float()</code> values with either my own comparison or <code>numpy.allclose()</code>.</p>

<p>Again, I'm not sure this is possible because monkey patching <code>float()</code> can't really be done since it's written in <code>C</code>.  I'd also like to avoid having to change every floating point value in the dicts to my own float class that has a <code>__eq__()</code>.  Maybe this is the <strong>best</strong> way though?</p>
