# Do not modify the original value of range so we can check for `None`
if range is None:
if a.size == 0:
# handle empty arrays. Can't determine range, so use 0-1.
mn, mx = 0.0, 1.0
else:
mn, mx = a.min() + 0.0, a.max() + 0.0
# add below
if not np.all(np.isfinite([mn, mx])):
b = a[np.isfinite(a)]
if b.size == 0:
mn, mx = 0., 1.
else:
mn, mx = b.min() + 0.0, b.max() + 0.0