@@ -327,8 +327,13 @@ def reset_minmax(self):
327327 color_value = color_value .astype (float )
328328 # ignore nan, -inf, inf (setting them to 0 or to very large numbers is not an option)
329329 color_value = color_value [np .isfinite (color_value )]
330- self .vmin = float (np .min (color_value ))
331- self .vmax = float (np .max (color_value ))
330+ if color_value .size :
331+ self .vmin = float (np .min (color_value ))
332+ self .vmax = float (np .max (color_value ))
333+ else :
334+ self .vmin = np .nan
335+ self .vmax = np .nan
336+
332337 self .bgcolor_possible = True
333338 # ValueError for empty arrays, TypeError for object/string arrays
334339 except (TypeError , ValueError ):
@@ -398,16 +403,23 @@ def data(self, index, role=Qt.DisplayRole):
398403 if self .bg_value is None :
399404 try :
400405 v = self .color_func (value ) if self .color_func is not None else value
401- if - np .inf < v < self .vmin :
402- # TODO: this is suboptimal, as it can reset many times (though in practice, it is usually
403- # ok). When we get buffering, we will need to compute vmin/vmax on the whole buffer
404- # at once, eliminating this problem (and we could even compute final colors directly
405- # all at once)
406- self .vmin = v
407- self .reset ()
408- elif self .vmax < v < np .inf :
409- self .vmax = v
410- self .reset ()
406+ if np .isnan (v ):
407+ v = np .nan
408+ else :
409+ do_reset = False
410+ if np .isnan (self .vmin ) or - np .inf < v < self .vmin :
411+ # TODO: this is suboptimal, as it can reset many times (though in practice, it is
412+ # usually ok). When we get buffering, we will need to compute vmin/vmax on the
413+ # whole buffer at once, eliminating this problem (and we could even compute final
414+ # colors directly all at once)
415+ self .vmin = v
416+ do_reset = True
417+ if np .isnan (self .vmax ) or self .vmax < v < np .inf :
418+ self .vmax = v
419+ do_reset = True
420+
421+ if do_reset :
422+ self .reset ()
411423 v = scale_to_01range (v , self .vmin , self .vmax )
412424 except TypeError :
413425 v = np .nan
0 commit comments