@@ -142,7 +142,7 @@ def __repr__(self) -> str:
142
142
)
143
143
return f"approx({ list_scalars !r} )"
144
144
145
- def _repr_compare (self , other_side : "ndarray" ) -> List [str ]:
145
+ def _repr_compare (self , other_side : Union [ "ndarray" , List [ Any ]] ) -> List [str ]:
146
146
import itertools
147
147
import math
148
148
@@ -163,10 +163,14 @@ def get_value_from_nested_list(
163
163
self ._approx_scalar , self .expected .tolist ()
164
164
)
165
165
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 :
167
171
return [
168
172
"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 } " ,
170
174
]
171
175
172
176
number_of_elements = self .expected .size
@@ -175,7 +179,7 @@ def get_value_from_nested_list(
175
179
different_ids = []
176
180
for index in itertools .product (* (range (i ) for i in np_array_shape )):
177
181
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 )
179
183
if approx_value != other_value :
180
184
abs_diff = abs (approx_value .expected - other_value )
181
185
max_abs_diff = max (max_abs_diff , abs_diff )
@@ -188,7 +192,7 @@ def get_value_from_nested_list(
188
192
message_data = [
189
193
(
190
194
str (index ),
191
- str (get_value_from_nested_list (other_side , index )),
195
+ str (get_value_from_nested_list (other_side_as_array , index )),
192
196
str (get_value_from_nested_list (approx_side_as_seq , index )),
193
197
)
194
198
for index in different_ids
0 commit comments