persistent_dict can't store NaNs
- Dominant language
- Python
- Stars
- 73
- Forks
- 26
- Avg merge
- 7h 3m
- Merged PRs (30d)
- 2
Description
```python
from pytools.persistent_dict import PersistentDict
import numpy as np
pdict = PersistentDict("pytools-test", safe_sync=True)
pdict[np.nan] = 42
assert pdict[np.nan] == 42
```
```console
$ python t.py
/Users/mdiener/Work/e12test/pytools/pytools/persistent_dict.py:602: CollisionWarning: pytools-test: key collision in cache at '/Users/mdiener/Work/e12test/loopy/xdg-cache/pytools' -- these are sufficiently unlikely that they're often indicative of a broken hash key implementation (that is not considering some elements relevant for equality comparison)
return self.fetch(key)
Traceback (most recent call last):
File "/Users/mdiener/Work/e12test/pytools/t.py", line 8, in
assert pdict[np.nan] == 42
~~~~~^^^^^^^^
File "/Users/mdiener/Work/e12test/pytools/pytools/persistent_dict.py", line 602, in __getitem__
return self.fetch(key)
^^^^^^^^^^^^^^^
File "/Users/mdiener/Work/e12test/pytools/pytools/persistent_dict.py", line 840, in fetch
self._collision_check(key, stored_key)
File "/Users/mdiener/Work/e12test/pytools/pytools/persistent_dict.py", line 552, in _collision_check
raise NoSuchEntryCollisionError(key)
pytools.persistent_dict.NoSuchEntryCollisionError: nan
```
🤦
Perhaps we should also check if the key contains a `Nan` in the collision check? Are there other cases that could be at issue here (`inf` seems to be fine)?
cc https://github.com/inducer/loopy/pull/828 [major plot twist!]
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.