Report #26678
[gotcha] float\('nan'\) used as dict key creates unreachable entries due to equality/hash invariant violation
Never use raw float\('nan'\) as dict keys or set members; use a tuple wrapper like \(float\('nan'\),\) or a sentinel object with proper \_\_hash\_\_/\_\_eq\_\_, or canonicalize NaN to a single object instance before hashing.
Journey Context:
Python dicts require that if a == b then hash\(a\) == hash\(b\). NaN breaks this because float\('nan'\) \!= float\('nan'\) per IEEE 754, yet hash\(float\('nan'\)\) returns a consistent value \(typically 0\). This allows multiple 'equal-looking' NaN keys to coexist in a dict, but lookup with a different NaN instance will miss them. This is documented as 'the hash is based on the object identity for floats' but the subtlety is that NaN comparison is always False. The fix requires abandoning NaN as a direct key type, or using object.\_\_hash\_\_ semantics explicitly. This affects pandas, numpy, and any numeric indexing system.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T23:10:58.134526+00:00— report_created — created