Skip to content

Cannot use np.dtype='bool' at all? #494

Closed
@doronbehar

Description

@doronbehar

Describe the bug

python -c "
from deepdiff import DeepHash 
import numpy as np
d = {'p': np.array([True], dtype='bool')}
print(DeepHash(d)[d])
"

Gives me:

8.0.0
Traceback (most recent call last):
  File "<string>", line 6, in <module>
  File "/nix/store/cv8dkyqwqbsdrjy1ji2nvxamvvy8ivsa-python3-3.12.6-env/lib/python3.12/site-packages/deepdiff/deephash.py", line 211, in __init__
    self._hash(obj, parent=parent, parents_ids=frozenset({get_id(obj)}))
  File "/nix/store/cv8dkyqwqbsdrjy1ji2nvxamvvy8ivsa-python3-3.12.6-env/lib/python3.12/site-packages/deepdiff/deephash.py", line 537, in _hash
    result, counts = self._prep_dict(obj=obj, parent=parent, parents_ids=parents_ids)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/cv8dkyqwqbsdrjy1ji2nvxamvvy8ivsa-python3-3.12.6-env/lib/python3.12/site-packages/deepdiff/deephash.py", line 401, in _prep_dict
    hashed, count = self._hash(item, parent=key_in_report, parents_ids=parents_ids_added)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/cv8dkyqwqbsdrjy1ji2nvxamvvy8ivsa-python3-3.12.6-env/lib/python3.12/site-packages/deepdiff/deephash.py", line 556, in _hash
    result, counts = self._prep_iterable(obj=obj, parent=parent, parents_ids=parents_ids)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/cv8dkyqwqbsdrjy1ji2nvxamvvy8ivsa-python3-3.12.6-env/lib/python3.12/site-packages/deepdiff/deephash.py", line 434, in _prep_iterable
    hashed, count = self._hash(item, parent=new_parent, parents_ids=parents_ids_added)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/cv8dkyqwqbsdrjy1ji2nvxamvvy8ivsa-python3-3.12.6-env/lib/python3.12/site-packages/deepdiff/deephash.py", line 561, in _hash
    result, counts = self._prep_obj(obj=obj, parent=parent, parents_ids=parents_ids)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/cv8dkyqwqbsdrjy1ji2nvxamvvy8ivsa-python3-3.12.6-env/lib/python3.12/site-packages/deepdiff/deephash.py", line 355, in _prep_obj
    result, counts = self._prep_dict(obj, parent=parent, parents_ids=parents_ids,
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/cv8dkyqwqbsdrjy1ji2nvxamvvy8ivsa-python3-3.12.6-env/lib/python3.12/site-packages/deepdiff/deephash.py", line 401, in _prep_dict
    hashed, count = self._hash(item, parent=key_in_report, parents_ids=parents_ids_added)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/cv8dkyqwqbsdrjy1ji2nvxamvvy8ivsa-python3-3.12.6-env/lib/python3.12/site-packages/deepdiff/deephash.py", line 503, in _hash
    result, counts = self.hashes[obj]
                     ~~~~~~~~~~~^^^^^
ValueError: memoryview: hashing is restricted to formats 'B', 'b' or 'c'

Why? Isn't a boolean datatype supposed to be the simplest dtype there is?

To Reproduce

Above.

Expected behavior

No error.

OS, DeepDiff version and Python version (please complete the following information):

  • OS: NixOS
  • Version nixos-unstable
  • Python Version 3.11 & 3.12
  • DeepDiff Version 8.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions