Example problem:
import numpy as np
dc = dict()
dc[np.float(\'nan\')] = 100
dc[np.float(\'nan\')] = 200
It is creating multiple entries for
As was mentioned in a comment to you, nan
is never "equal" to another nan
, do your dict
is writing a new key for it. This is the behavior for nan
values in most languages, not just python.
I would suggest not using it as a key at all, or at least explain the purpose of it so we can find better ways to achieve that purpose without falling into pitfalls like this.
In your case you could test this bahavior for yourself:
a=list(dc.keys())
print(a[0]==a[1]) # will output False
The output for the above code (False
) means that for the system, the are in fact different keys that do not clash