@@ -142,7 +142,7 @@ def __repr__(self) -> str:
142142 )
143143 return f"approx({ list_scalars !r} )"
144144
145- def _repr_compare (self , other_side : "ndarray" ) -> List [str ]:
145+ def _repr_compare (self , other_side : Union [ "ndarray" , List [ Any ]] ) -> List [str ]:
146146 import itertools
147147 import math
148148
@@ -163,10 +163,14 @@ def get_value_from_nested_list(
163163 self ._approx_scalar , self .expected .tolist ()
164164 )
165165
166- if np_array_shape != other_side .shape :
166+ # Convert other_side to numpy array to ensure shape attribute is available.
167+ other_side_as_array = _as_numpy_array (other_side )
168+ assert other_side_as_array is not None
169+
170+ if np_array_shape != other_side_as_array .shape :
167171 return [
168172 "Impossible to compare arrays with different shapes." ,
169- f"Shapes: { np_array_shape } and { other_side .shape } " ,
173+ f"Shapes: { np_array_shape } and { other_side_as_array .shape } " ,
170174 ]
171175
172176 number_of_elements = self .expected .size
@@ -175,7 +179,7 @@ def get_value_from_nested_list(
175179 different_ids = []
176180 for index in itertools .product (* (range (i ) for i in np_array_shape )):
177181 approx_value = get_value_from_nested_list (approx_side_as_seq , index )
178- other_value = get_value_from_nested_list (other_side , index )
182+ other_value = get_value_from_nested_list (other_side_as_array , index )
179183 if approx_value != other_value :
180184 abs_diff = abs (approx_value .expected - other_value )
181185 max_abs_diff = max (max_abs_diff , abs_diff )
@@ -188,7 +192,7 @@ def get_value_from_nested_list(
188192 message_data = [
189193 (
190194 str (index ),
191- str (get_value_from_nested_list (other_side , index )),
195+ str (get_value_from_nested_list (other_side_as_array , index )),
192196 str (get_value_from_nested_list (approx_side_as_seq , index )),
193197 )
194198 for index in different_ids
0 commit comments