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

DeepHash fails on 0-d-np.array #332

Open
volkerjaenisch opened this issue Aug 2, 2022 · 5 comments
Open

DeepHash fails on 0-d-np.array #332

volkerjaenisch opened this issue Aug 2, 2022 · 5 comments

Comments

@volkerjaenisch
Copy link

I do like DeepDiff/DeepHash really!

But today I think I found an error:

import numpy as np
from deepdiff import DeepHash

a=np.array(2)
DeepHash(a)
Traceback (most recent call last):
  File "/home/volker/workspace/PYTHON5/zeiss_caching/zeiss_caching/sandbox.py", line 23, in <module>
    DeepHash(a)
  File "/home/volker/workspace/venvs/zeiss-caching-O3myIkpD-py3.9/lib/python3.9/site-packages/deepdiff/deephash.py", line 190, in __init__
    self._hash(obj, parent=parent, parents_ids=frozenset({get_id(obj)}))
  File "/home/volker/workspace/venvs/zeiss-caching-O3myIkpD-py3.9/lib/python3.9/site-packages/deepdiff/deephash.py", line 483, in _hash
    result, counts = self._prep_iterable(obj=obj, parent=parent, parents_ids=parents_ids)
  File "/home/volker/workspace/venvs/zeiss-caching-O3myIkpD-py3.9/lib/python3.9/site-packages/deepdiff/deephash.py", line 383, in _prep_iterable
    for i, item in enumerate(obj):
TypeError: iteration over a 0-d array

Expected behavior
A hash should be created

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

  • OS: Debian Bullseye
  • Python: 3.9.2
  • DeepDiff: 5.8.1

Additional Context
DeepDiv also behaves weird with 0-d-arrays

a=np.array(2)
b=np.array(2)
print(DeepDiff(a, b))
{}
a=np.array(2)
b=np.array(3)
print(DeepDiff(a, b))

Traceback (most recent call last):
  File "/home/volker/workspace/venvs/zeiss-caching-O3myIkpD-py3.9/lib/python3.9/site-packages/deepdiff/diff.py", line 296, in __init__
    self._diff(root, parents_ids=frozenset({id(t1)}), _original_type=_original_type)
  File "/home/volker/workspace/venvs/zeiss-caching-O3myIkpD-py3.9/lib/python3.9/site-packages/deepdiff/diff.py", line 1348, in _diff
    self._diff_numpy_array(level, parents_ids)
  File "/home/volker/workspace/venvs/zeiss-caching-O3myIkpD-py3.9/lib/python3.9/site-packages/deepdiff/diff.py", line 1223, in _diff_numpy_array
    self._diff_iterable_in_order(new_level, parents_ids, _original_type=_original_type)
  File "/home/volker/workspace/venvs/zeiss-caching-O3myIkpD-py3.9/lib/python3.9/site-packages/deepdiff/diff.py", line 669, in _diff_iterable_in_order
    for (i, j), (x, y) in self._get_matching_pairs(level):
  File "/home/volker/workspace/venvs/zeiss-caching-O3myIkpD-py3.9/lib/python3.9/site-packages/deepdiff/diff.py", line 619, in _get_matching_pairs
    return self._compare_in_order(level)
  File "/home/volker/workspace/venvs/zeiss-caching-O3myIkpD-py3.9/lib/python3.9/site-packages/deepdiff/diff.py", line 603, in _compare_in_order
    zip_longest(
TypeError: iteration over a 0-d array

Cheers,
Volker

@volkerjaenisch volkerjaenisch changed the title DeepHash fails on 0-d-nparray DeepHash fails on 0-d-np.array Aug 2, 2022
@seperman
Copy link
Owner

@volkerjaenisch Thanks for reporting the bug. I will take a look at it when I have a chance. Of course PRs are very welcome if you would like to contribute a solution.

@volkerjaenisch
Copy link
Author

volkerjaenisch commented Aug 14, 2022 via email

@seperman
Copy link
Owner

oh, sorry to hear that. That sucks. I hope you will heal soon and be back on the bike.

@volkerjaenisch
Copy link
Author

volkerjaenisch commented Aug 15, 2022 via email

@piyush-kansal
Copy link

piyush-kansal commented Nov 29, 2023

I am also hitting the same issue while trying to calculate DeepHash of an model object during training.

Until a formal fix is released, is there is a quick hack that I could apply on my side to solve this issue @seperman ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants