[issue43475] Worst-case behaviour of hash collision with float NaN

Raymond Hettinger report at bugs.python.org
Sun Apr 11 01:27:17 EDT 2021


Raymond Hettinger <raymond.hettinger at gmail.com> added the comment:

> I'm loathe to guarantee anything about this in the language itself. 

There aren't language any guarantees being proposed.  Letting the hash depend on the object id just helps avoid quadratic behavior.  Making float('NaN') a singleton is also perfectly reasonable behavior for an immutable type.  Neither is a guaranteed behavior, just a convenient one.


> I'm not convinced it addresses a real-world problem

Maybe yes, maybe no.  I would hope that NaNs arising from bogus calculations would be rare.  OTOH, they are commonly used for missing values in Pandas where internal dict/set operations abound.  Either way, I would like to close off a trivially easy way to invoke quadratic behavior unexpectedly.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43475>
_______________________________________


More information about the Python-bugs-list mailing list