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: check numpy booleans like native booleans #496

Merged
merged 2 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion deepdiff/deephash.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
import polars
except ImportError:
polars = False
try:
import numpy as np
booleanTypes = (bool, np.bool_)
except ImportError:
booleanTypes = bool

Check warning on line 31 in deepdiff/deephash.py

View check run for this annotation

Codecov / codecov/patch

deepdiff/deephash.py#L30-L31

Added lines #L30 - L31 were not covered by tests

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -492,7 +497,7 @@
"""The main hash method"""
counts = 1

if isinstance(obj, bool):
if isinstance(obj, booleanTypes):
obj = self._prep_bool(obj)
result = None
elif self.use_enum_value and isinstance(obj, Enum):
Expand Down
6 changes: 6 additions & 0 deletions tests/test_hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,12 @@ def test_re(self):
a_hash = DeepHash(a)[a]
assert not( a_hash is unprocessed)

# https://github.com/seperman/deepdiff/issues/494
def test_numpy_bool(self):
a = {'b': np.array([True], dtype='bool')}
a_hash = DeepHash(a)[a]
assert not( a_hash is unprocessed)

class TestDeepHashPrep:
"""DeepHashPrep Tests covering object serialization."""

Expand Down
Loading