Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyBuilder: warn on encountering NaN #288

Merged
merged 4 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions pytools/persistent_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,14 @@
key_hash.update(str(key).encode("utf8"))

def update_for_float(self, key_hash: Hash, key: float) -> None:
import math
if math.isnan(key):
# Also applies to np.nan, float("nan")
warn("Encountered a NaN while hashing. Since NaNs compare unequal "

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.10 ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.10 ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.10 ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.10 ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.10 ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.10 ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.10 ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.10 ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.10 ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.10 ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest without Numpy

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest without Numpy

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest without Numpy

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest without Numpy

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest without Numpy

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest without Numpy

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest without Numpy

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest without Numpy

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.12 ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.12 ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.12 ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.12 ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.12 ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.12 ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.12 ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.12 ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.12 ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.12 ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.x ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.x ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.x ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.x ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.x ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.x ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.x ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.x ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.x ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.x ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.12 macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.12 macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.12 macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.12 macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.12 macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.12 macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.12 macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.12 macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.12 macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.12 macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.10 macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.10 macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.10 macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.10 macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.10 macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.10 macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.10 macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.10 macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.10 macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.10 macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.x macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.x macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.x macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.x macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.x macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.x macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.x macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.x macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.x macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.x macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Pypypy3.10 ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Pypypy3.10 ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Pypypy3.10 ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Pypypy3.10 ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Pypypy3.10 ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Pypypy3.10 ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Pypypy3.10 ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Pypypy3.10 ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Pypypy3.10 ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Pypypy3.10 ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Pypypy3.10 macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Pypypy3.10 macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Pypypy3.10 macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Pypypy3.10 macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Pypypy3.10 macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Pypypy3.10 macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Pypypy3.10 macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Pypypy3.10 macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Pypypy3.10 macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 297 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Pypypy3.10 macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.
"to themselves, the resulting key can not be retrieved from a "
"PersistentDict and will lead to a collision error on retrieval.",
stacklevel=1)

key_hash.update(key.hex().encode("utf8"))

def update_for_complex(self, key_hash: Hash, key: float) -> None:
Expand Down Expand Up @@ -661,6 +669,12 @@
and if they occur, almost always due to a bug in the hash key
generation code (:class:`KeyBuilder`).

.. warning::

Since NaNs compare unequal to themselves, keys that include NaNs can
not be retrieved from a :class:`WriteOncePersistentDict` and will lead to a
:exc:`NoSuchEntryCollisionError` on retrieval.

.. automethod:: __init__
.. automethod:: __getitem__
.. automethod:: __setitem__
Expand Down Expand Up @@ -774,6 +788,12 @@
and if they occur, almost always due to a bug in the hash key
generation code (:class:`KeyBuilder`).

.. warning::

Since NaNs compare unequal to themselves, keys that include NaNs can
not be retrieved from a :class:`PersistentDict` and will lead to a
:exc:`NoSuchEntryCollisionError` on retrieval.

.. automethod:: __init__
.. automethod:: __getitem__
.. automethod:: __setitem__
Expand Down
34 changes: 34 additions & 0 deletions pytools/test/test_persistent_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,40 @@ def test_concurrency_threads() -> None:
# }}}


def test_nan_keys() -> None:
# test for https://github.com/inducer/pytools/issues/287

try:
tmpdir = tempfile.mkdtemp()
keyb = KeyBuilder()
pdict: PersistentDict[float, int] = PersistentDict("pytools-test",
container_dir=tmpdir,
safe_sync=False,
key_builder=keyb)

import math

nan_values = [math.nan, float("nan")]

try:
import numpy as np
nan_values.append(np.nan)
except ImportError:
pass

for nan_value in nan_values:
assert nan_value != nan_value
assert keyb(nan_value) == keyb(nan_value)

pdict[nan_value] = 42

with (pytest.warns(CollisionWarning),
pytest.raises(NoSuchEntryCollisionError)):
pdict[math.nan]
finally:
shutil.rmtree(tmpdir)


if __name__ == "__main__":
if len(sys.argv) > 1:
exec(sys.argv[1])
Expand Down
Loading