Skip to content

Commit 5302762

Browse files
committed
add a fix
1 parent f863c78 commit 5302762

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

codeflash/verification/comparator.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,8 @@ def comparator(orig: Any, new: Any, superset_obj=False) -> bool: # noqa: ANN001
127127
if isinstance(orig, tf.SparseTensor):
128128
if not comparator(orig.dense_shape.numpy(), new.dense_shape.numpy(), superset_obj):
129129
return False
130-
return (
131-
comparator(orig.indices.numpy(), new.indices.numpy(), superset_obj) and
132-
comparator(orig.values.numpy(), new.values.numpy(), superset_obj)
130+
return comparator(orig.indices.numpy(), new.indices.numpy(), superset_obj) and comparator(
131+
orig.values.numpy(), new.values.numpy(), superset_obj
133132
)
134133

135134
if isinstance(orig, tf.RaggedTensor):
@@ -182,8 +181,8 @@ def comparator(orig: Any, new: Any, superset_obj=False) -> bool: # noqa: ANN001
182181
# dict_values need element-wise comparison (order matters)
183182
return comparator(list(orig), list(new))
184183
if type_name == "dict_items":
185-
# dict_items can be compared as sets of tuples (order doesn't matter for items)
186-
return comparator(list(orig), list(new))
184+
# Convert to dict for order-insensitive comparison (handles unhashable values)
185+
return comparator(dict(orig), dict(new), superset_obj)
187186

188187
if HAS_NUMPY:
189188
import numpy as np # type: ignore # noqa: PGH003

tests/test_comparator.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1838,6 +1838,7 @@ def test_dict_views() -> None:
18381838
i3 = {"a": 1, "b": 2, "c": 4} # different value
18391839
i4 = {"a": 1, "b": 2, "d": 3} # different key
18401840
i5 = {"a": 1, "b": 2} # different length
1841+
i6 = {"b": 2, "c": 3, "a": 1} # different order
18411842

18421843
# dict_items - same items
18431844
assert comparator(i1.items(), i2.items())
@@ -1848,6 +1849,8 @@ def test_dict_views() -> None:
18481849
# dict_items - different length
18491850
assert not comparator(i1.items(), i5.items())
18501851

1852+
assert comparator(i1.items(), i6.items())
1853+
18511854
# Test empty dicts
18521855
empty1 = {}
18531856
empty2 = {}

0 commit comments

Comments
 (0)