Skip to content

Commit 4bd7d02

Browse files
committed
update comparator for np.void
1 parent 22560c0 commit 4bd7d02

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

codeflash/verification/comparator.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ def comparator(orig: Any, new: Any, superset_obj=False) -> bool:
148148
if HAS_NUMPY and isinstance(orig, (np.integer, np.bool_, np.byte)):
149149
return orig == new
150150

151+
if HAS_NUMPY and isinstance(orig, np.void):
152+
if orig.dtype != new.dtype:
153+
return False
154+
return all(comparator(orig[field], new[field], superset_obj) for field in orig.dtype.fields)
155+
151156
if HAS_SCIPY and isinstance(orig, scipy.sparse.spmatrix):
152157
if orig.dtype != new.dtype:
153158
return False

tests/test_comparator.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,20 @@ def test_numpy():
298298
assert comparator(ak, al)
299299
assert not comparator(ai, ak)
300300

301+
dt = np.dtype([('name', 'S10'), ('age', np.int32)])
302+
a_struct = np.array([('Alice', 25)], dtype=dt)
303+
b_struct = np.array([('Alice', 25)], dtype=dt)
304+
c_struct = np.array([('Bob', 30)], dtype=dt)
305+
306+
a_void = a_struct[0]
307+
b_void = b_struct[0]
308+
c_void = c_struct[0]
309+
310+
assert isinstance(a_void, np.void)
311+
assert comparator(a_void, b_void)
312+
assert not comparator(a_void, c_void)
313+
314+
301315

302316
def test_scipy():
303317
try:

0 commit comments

Comments
 (0)