@@ -165,42 +165,45 @@ def get_data_diff(files, max_abs=0, max_rel=0):
165165
166166 for j , d2 in enumerate (data [i + 1 :], i + 1 ):
167167
168- abs_diff = np .abs (d1 - d2 )
169- mean_abs = (np .abs (d1 ) + np .abs (d2 )) * 0.5
170- candidates = np .logical_or (mean_abs != 0 , abs_diff != 0 )
171-
172- if max_abs :
173- candidates [abs_diff <= max_abs ] = False
174-
175- max_abs_diff = np .max (abs_diff )
176- if np .any (candidates ):
177- rel_diff = abs_diff [candidates ] / mean_abs [candidates ]
178- if max_rel :
179- sub_thr = rel_diff <= max_rel
180- # Since we operated on sub-selected values already, we need
181- # to plug them back in
182- candidates [
183- tuple ((indexes [sub_thr ] for indexes in np .where (candidates )))
184- ] = False
185- max_rel_diff = np .max (rel_diff )
186- else :
187- max_rel_diff = 0
188-
189- if np .any (candidates ):
168+ if d1 .shape == d2 .shape :
169+ abs_diff = np .abs (d1 - d2 )
170+ mean_abs = (np .abs (d1 ) + np .abs (d2 )) * 0.5
171+ candidates = np .logical_or (mean_abs != 0 , abs_diff != 0 )
172+
173+ if max_abs :
174+ candidates [abs_diff <= max_abs ] = False
175+
176+ max_abs_diff = np .max (abs_diff )
177+ if np .any (candidates ):
178+ rel_diff = abs_diff [candidates ] / mean_abs [candidates ]
179+ if max_rel :
180+ sub_thr = rel_diff <= max_rel
181+ # Since we operated on sub-selected values already, we need
182+ # to plug them back in
183+ candidates [
184+ tuple ((indexes [sub_thr ] for indexes in np .where (candidates )))
185+ ] = False
186+ max_rel_diff = np .max (rel_diff )
187+ else :
188+ max_rel_diff = 0
189+
190+ if np .any (candidates ):
191+
192+ diff_rec = OrderedDict () # so that abs goes before relative
193+
194+ diff_rec ['abs' ] = max_abs_diff
195+ diff_rec ['rel' ] = max_rel_diff
196+ diffs1 .append (diff_rec )
197+ else :
198+ diffs1 .append (None )
190199
191- diff_rec = OrderedDict () # so that abs goes before relative
192-
193- diff_rec ['abs' ] = max_abs_diff
194- diff_rec ['rel' ] = max_rel_diff
195- diffs1 .append (diff_rec )
196200 else :
197- diffs1 .append (None )
201+ diffs1 .append ({ 'CMP' : "incompat" } )
198202
199203 if any (diffs1 ):
200204
201205 diffs ['DATA(diff %d:)' % (i + 1 )] = diffs1
202206
203-
204207 return diffs
205208
206209
@@ -219,13 +222,14 @@ def display_diff(files, diff):
219222 """
220223 output = ""
221224 field_width = "{:<15}"
225+ filename_width = "{:<53}"
222226 value_width = "{:<55}"
223227
224228 output += "These files are different.\n "
225229 output += field_width .format ('Field/File' )
226230
227231 for i , f in enumerate (files , 1 ):
228- output += "%d:%s" % (i , value_width .format (os .path .basename (f )))
232+ output += "%d:%s" % (i , filename_width .format (os .path .basename (f )))
229233
230234 output += "\n "
231235
0 commit comments