Skip to content
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
8 changes: 8 additions & 0 deletions codeflash/verification/comparator.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import array
import ast
import datetime
import decimal
Expand Down Expand Up @@ -170,6 +171,13 @@ def comparator(orig: Any, new: Any, superset_obj=False) -> bool:
if HAS_PANDAS and pandas.isna(orig) and pandas.isna(new):
return True

if isinstance(orig, array.array):
if orig.typecode != new.typecode:
return False
if len(orig) != len(new):
return False
return all(comparator(elem1, elem2, superset_obj) for elem1, elem2 in zip(orig, new))

# This should be at the end of all numpy checking
try:
if HAS_NUMPY and np.isnan(orig):
Expand Down
19 changes: 19 additions & 0 deletions tests/test_comparator.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import sys
from enum import Enum, Flag, IntFlag, auto
from pathlib import Path
import array # Add import for array

import pydantic
import pytest
Expand Down Expand Up @@ -203,6 +204,24 @@ class Color4(IntFlag):
assert not comparator(a, c)
assert not comparator(a, d)

arr1 = array.array('i', [1, 2, 3])
arr2 = array.array('i', [1, 2, 3])
arr3 = array.array('i', [4, 5, 6])
arr4 = array.array('f', [1.0, 2.0, 3.0])

assert comparator(arr1, arr2)
assert not comparator(arr1, arr3)
assert not comparator(arr1, arr4)
assert not comparator(arr1, [1, 2, 3])

empty_arr_i1 = array.array('i')
empty_arr_i2 = array.array('i')
empty_arr_f = array.array('f')
assert comparator(empty_arr_i1, empty_arr_i2)
assert not comparator(empty_arr_i1, empty_arr_f)
assert not comparator(empty_arr_i1, arr1)



def test_numpy():
try:
Expand Down
Loading