diff --git a/pytools/persistent_dict.py b/pytools/persistent_dict.py index 8fd6f849a87c410757022f740ccf2be1f261bc72..8d8d06ddf33ecd475d108bd7ef595055f87d6fb9 100644 --- a/pytools/persistent_dict.py +++ b/pytools/persistent_dict.py @@ -238,9 +238,14 @@ class KeyBuilder: try: method = getattr(self, "update_for_"+tname) except AttributeError: - # Handling numpy >= 1.20, for which - # type(np.dtype("float32")) -> "dtype[float32]" - if tname.startswith("dtype[") and "numpy" in sys.modules: + if ( + # Handling numpy >= 1.20, for which + # type(np.dtype("float32")) -> "dtype[float32]" + tname.startswith("dtype[") + # Handling numpy >= 1.25, for which + # type(np.dtype("float32")) -> "Float32DType" + or tname.endswith("DType") + ) and "numpy" in sys.modules: import numpy as np if isinstance(key, np.dtype): method = self.update_for_specific_dtype diff --git a/test/test_persistent_dict.py b/test/test_persistent_dict.py index a64b71833379b5fe4d4593a98966fddde50564fc..59dd49139aaf827995ce0fde9e263e34fccaa79c 100644 --- a/test/test_persistent_dict.py +++ b/test/test_persistent_dict.py @@ -7,8 +7,8 @@ from enum import Enum, IntEnum import pytest from pytools.persistent_dict import ( - CollisionWarning, NoSuchEntryError, PersistentDict, ReadOnlyEntryError, - WriteOncePersistentDict) + CollisionWarning, KeyBuilder, NoSuchEntryError, PersistentDict, + ReadOnlyEntryError, WriteOncePersistentDict) from pytools.tag import Tag, tag_dataclass @@ -372,6 +372,14 @@ def test_write_once_persistent_dict_clear(): shutil.rmtree(tmpdir) +def test_dtype_hashing(): + np = pytest.importorskip("numpy") + + keyb = KeyBuilder() + assert keyb(np.float32) == keyb(np.float32) + assert keyb(np.dtype(np.float32)) == keyb(np.dtype(np.float32)) + + if __name__ == "__main__": if len(sys.argv) > 1: exec(sys.argv[1])