# Buggy code
def _update_thumbnail(self):
    """Update thumbnail with current image data and colormap."""
    if self.dims.ndisplay == 3 and self.dims.ndim > 2:
        image = np.max(self._data_thumbnail, axis=0)
    else:
        image = self._data_thumbnail

    # float16 not supported by ndi.zoom
    dtype = np.dtype(image.dtype)
    if dtype in [np.dtype(np.float16)]:
        image = image.astype(np.float32)

    zoom_factor = np.divide(self._thumbnail_shape[:2], image.shape[:2]).min()
    if self.rgb:
        # warning filter can be removed with scipy 1.4
        with warnings.catch_warnings():
            warnings.simplefilter("ignore")
            downsampled = ndi.zoom(
                image,
                (zoom_factor, zoom_factor, 1),
                prefilter=False,
                order=0,
            )
        if image.shape[2] == 4:  # image is RGBA
            colormapped = np.copy(downsampled)
            colormapped[..., 3] = downsampled[..., 3] * self.opacity
            if downsampled.dtype == np.uint8:
                colormapped = colormapped.astype(np.uint8)
        else:  # image is RGB
            if downsampled.dtype == np.uint8:
                alpha = np.full(
                    downsampled.shape[:2] + (1,),
                    int(255 * self.opacity),
                    dtype=np.uint8,
                )
            else:
                alpha = np.full(downsampled.shape[:2] + (1,), self.opacity)
            colormapped = np.concatenate([downsampled, alpha], axis=2)
    else:
        # warning filter can be removed with scipy 1.4
        with warnings.catch_warnings():
            warnings.simplefilter("ignore")
            downsampled = ndi.zoom(image, zoom_factor, prefilter=False, order=0)
        low, high = self.contrast_limits
        downsampled = np.clip(downsampled, low, high)
        color_range = high - low
        if color_range != 0:
            downsampled = (downsampled - low) / color_range
        downsampled = downsampled**self.gamma
        color_array = self.colormap[1][downsampled.ravel()]
        colormapped = color_array.rgba.reshape(downsampled.shape + (4,))
        colormapped[..., 3] *= self.opacity
    self.thumbnail = colormapped


# Traceback (ValueError)
WARNING: Traceback (most recent call last):
File "/usr/lib/python3.7/site-packages/napari/_qt/qt_viewer_buttons.py", line 121, in <lambda>
self.clicked.connect(lambda: self.viewer.dims._roll())
File "/usr/lib/python3.7/site-packages/napari/components/dims.py", line 340, in _roll
self.order = np.roll(self.order, 1)
File "/usr/lib/python3.7/site-packages/napari/components/dims.py", line 130, in order
self.events.order()
File "/usr/lib/python3.7/site-packages/napari/util/event.py", line 508, in __call__
self._invoke_callback(cb, event)
File "/usr/lib/python3.7/site-packages/napari/util/event.py", line 529, in _invoke_callback
cb_event=(cb, event),
File "/usr/lib/python3.7/site-packages/napari/util/event.py", line 523, in _invoke_callback
cb(event)
File "/usr/lib/python3.7/site-packages/napari/components/viewer_model.py", line 88, in <lambda>
self.dims.events.order.connect(lambda e: self._update_layers())
File "/usr/lib/python3.7/site-packages/napari/components/viewer_model.py", line 1045, in _update_layers
layer.dims.order = order
File "/usr/lib/python3.7/site-packages/napari/components/dims.py", line 130, in order
self.events.order()
File "/usr/lib/python3.7/site-packages/napari/util/event.py", line 508, in __call__
self._invoke_callback(cb, event)
File "/usr/lib/python3.7/site-packages/napari/util/event.py", line 529, in _invoke_callback
cb_event=(cb, event),
File "/usr/lib/python3.7/site-packages/napari/util/event.py", line 523, in _invoke_callback
cb(event)
File "/usr/lib/python3.7/site-packages/napari/layers/base/base.py", line 176, in <lambda>
self.dims.events.order.connect(lambda e: self._update_dims())
File "/usr/lib/python3.7/site-packages/napari/layers/base/base.py", line 373, in _update_dims
self._set_view_slice()
File "/usr/lib/python3.7/site-packages/napari/layers/image/image.py", line 477, in _set_view_slice
self._update_thumbnail()
File "/usr/lib/python3.7/site-packages/napari/layers/image/image.py", line 536, in _update_thumbnail
color_array = self.colormap[1][downsampled.ravel()]
File "/usr/lib/python3.7/site-packages/vispy/color/colormap.py", line 293, in __getitem__
return ColorArray(colors)
File "/usr/lib/python3.7/site-packages/vispy/color/color_array.py", line 148, in __init__
rgba = _user_to_rgba(color, clip=clip)
File "/usr/lib/python3.7/site-packages/vispy/color/color_array.py", line 61, in _user_to_rgba
if color.min() < 0 or color.max() > 1:
File "/usr/lib/python3.7/site-packages/numpy/core/_methods.py", line 32, in _amin
return umr_minimum(a, axis, None, out, keepdims, initial)
ValueError: zero-size array to reduction operation minimum which has no identity
WARNING:vispy:Traceback (most recent call last):
File "/usr/lib/python3.7/site-packages/napari/_qt/qt_viewer_buttons.py", line 121, in <lambda>
self.clicked.connect(lambda: self.viewer.dims._roll())
File "/usr/lib/python3.7/site-packages/napari/components/dims.py", line 340, in _roll
self.order = np.roll(self.order, 1)
File "/usr/lib/python3.7/site-packages/napari/components/dims.py", line 130, in order
self.events.order()
File "/usr/lib/python3.7/site-packages/napari/util/event.py", line 508, in __call__
self._invoke_callback(cb, event)
File "/usr/lib/python3.7/site-packages/napari/util/event.py", line 529, in _invoke_callback
cb_event=(cb, event),
File "/usr/lib/python3.7/site-packages/napari/util/event.py", line 523, in _invoke_callback
cb(event)
File "/usr/lib/python3.7/site-packages/napari/components/viewer_model.py", line 88, in <lambda>
self.dims.events.order.connect(lambda e: self._update_layers())
File "/usr/lib/python3.7/site-packages/napari/components/viewer_model.py", line 1045, in _update_layers
layer.dims.order = order
File "/usr/lib/python3.7/site-packages/napari/components/dims.py", line 130, in order
self.events.order()
File "/usr/lib/python3.7/site-packages/napari/util/event.py", line 508, in __call__
self._invoke_callback(cb, event)
File "/usr/lib/python3.7/site-packages/napari/util/event.py", line 529, in _invoke_callback
cb_event=(cb, event),
File "/usr/lib/python3.7/site-packages/napari/util/event.py", line 523, in _invoke_callback
cb(event)
File "/usr/lib/python3.7/site-packages/napari/layers/base/base.py", line 176, in <lambda>
self.dims.events.order.connect(lambda e: self._update_dims())
File "/usr/lib/python3.7/site-packages/napari/layers/base/base.py", line 373, in _update_dims
self._set_view_slice()
File "/usr/lib/python3.7/site-packages/napari/layers/image/image.py", line 477, in _set_view_slice
self._update_thumbnail()
File "/usr/lib/python3.7/site-packages/napari/layers/image/image.py", line 536, in _update_thumbnail
color_array = self.colormap[1][downsampled.ravel()]
File "/usr/lib/python3.7/site-packages/vispy/color/colormap.py", line 293, in __getitem__
return ColorArray(colors)
File "/usr/lib/python3.7/site-packages/vispy/color/color_array.py", line 148, in __init__
rgba = _user_to_rgba(color, clip=clip)
File "/usr/lib/python3.7/site-packages/vispy/color/color_array.py", line 61, in _user_to_rgba
if color.min() < 0 or color.max() > 1:
File "/usr/lib/python3.7/site-packages/numpy/core/_methods.py", line 32, in _amin
return umr_minimum(a, axis, None, out, keepdims, initial)
ValueError: zero-size array to reduction operation minimum which has no identity
[1]    16296 abort (core dumped)  napari FITC.tif

# Fixed code
def _update_thumbnail(self):
    """Update thumbnail with current image data and colormap."""
    if self.dims.ndisplay == 3 and self.dims.ndim > 2:
        image = np.max(self._data_thumbnail, axis=0)
    else:
        image = self._data_thumbnail

    # float16 not supported by ndi.zoom
    dtype = np.dtype(image.dtype)
    if dtype in [np.dtype(np.float16)]:
        image = image.astype(np.float32)

    raw_zoom_factor = np.divide(self._thumbnail_shape[:2], image.shape[:2]).min()
    new_shape = np.clip(
        raw_zoom_factor * np.array(image.shape[:2]),
        1,  # smallest side should be 1 pixel wide
        self._thumbnail_shape[:2],
    )
    zoom_factor = tuple(new_shape / image.shape[:2])
    if self.rgb:
        # warning filter can be removed with scipy 1.4
        with warnings.catch_warnings():
            warnings.simplefilter("ignore")
            downsampled = ndi.zoom(image, zoom_factor + (1,), prefilter=False, order=0)
        if image.shape[2] == 4:  # image is RGBA
            colormapped = np.copy(downsampled)
            colormapped[..., 3] = downsampled[..., 3] * self.opacity
            if downsampled.dtype == np.uint8:
                colormapped = colormapped.astype(np.uint8)
        else:  # image is RGB
            if downsampled.dtype == np.uint8:
                alpha = np.full(
                    downsampled.shape[:2] + (1,),
                    int(255 * self.opacity),
                    dtype=np.uint8,
                )
            else:
                alpha = np.full(downsampled.shape[:2] + (1,), self.opacity)
            colormapped = np.concatenate([downsampled, alpha], axis=2)
    else:
        # warning filter can be removed with scipy 1.4
        with warnings.catch_warnings():
            warnings.simplefilter("ignore")
            downsampled = ndi.zoom(image, zoom_factor, prefilter=False, order=0)
        low, high = self.contrast_limits
        downsampled = np.clip(downsampled, low, high)
        color_range = high - low
        if color_range != 0:
            downsampled = (downsampled - low) / color_range
        downsampled = downsampled**self.gamma
        color_array = self.colormap[1][downsampled.ravel()]
        colormapped = color_array.rgba.reshape(downsampled.shape + (4,))
        colormapped[..., 3] *= self.opacity
    self.thumbnail = colormapped