Skip to content

Recursion depth limit when hashing numpy.datetime64 #534

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

Open
jcipar opened this issue Mar 25, 2025 · 2 comments
Open

Recursion depth limit when hashing numpy.datetime64 #534

jcipar opened this issue Mar 25, 2025 · 2 comments

Comments

@jcipar
Copy link

jcipar commented Mar 25, 2025

Describe the bug
When hashing a numpy.datetime64 deepdiff.DeepHash fails with RecursionError: maximum recursion depth exceeded.

This can be fixed by adding numpy.datetime64 to deepdiff.helper.times.

To Reproduce
This is a test case that demonstrates the problem:

from deepdiff import DeepHash
import numpy as np

def test_hash_datetime():
    DeepHash(np.datetime64("2025-03-25T11:15:04Z"))

This is a monkeypatch that I'm using to work around the problem:

import deepdiff.deephash
import deepdiff.helper
import numpy as np

deepdiff.helper.times = (*deepdiff.helper.times, np.datetime64,)
deepdiff.deephash.times = deepdiff.helper.times

Expected behavior
It produces a hash value for the datetime64.

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

  • OS: MacOS
  • Version: Darwin Darwin Kernel Version 23.6.0: Fri Jul 5 17:55:37 PDT 2024; root:xnu-10063.141.1~2/RELEASE_ARM64_T6030 arm64
  • Python Version: 3.12.8
  • DeepDiff Version: 8.4.2
  • Numpy Version: 2.2.4

Additional context
It looks like there's some other stuff in deepdiff.helper that might be relevant. For instance, the datetimes tuple also doesn't have numpy.datetime64, but adding it there seems unnecessary to fix this issue. It looks like the only use of datetimes is to add to the numbers tuple, and I'm not sure whether this should be considered a number.

@seperman
Copy link
Owner

Hi @jcipar
Thanks for the detailed explanation. Do you want to make a PR? You can then add yourself to the contributors list too. And please include unit tests.
We do check for isinstance(obj, datetimes) btw and convert datetimes to proper timezone for comparison.

@jcipar
Copy link
Author

jcipar commented Mar 29, 2025

Sounds good, I can have something ready shortly. I'm not sure where you'd prefer the tests for diffing. It seems like both test_diff_numpy and test_diff_datetime would make sense.

jcipar added a commit to jcipar/deepdiff that referenced this issue Mar 29, 2025
This fixes the bug described in [issue 534](seperman#534).
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

2 participants