# Buggy code
def _update_thumbnail(self):
    """Update thumbnail with current image data and colormap."""
    if self.dims.ndisplay == 3:
        image = np.max(self._data_thumbnail, axis=0)
    else:
        image = self._data_thumbnail
    zoom_factor = np.divide(self._thumbnail_shape[:2], image.shape[:2]).min()
    if self.multichannel:
        # 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
        colormapped = self.colormap[1].map(downsampled)
        colormapped = colormapped.reshape(downsampled.shape + (4,))
        colormapped[..., 3] *= self.opacity
    self.thumbnail = colormapped


# Traceback (ValueError)
WARNING: Traceback (most recent call last):
File "/Users/royer/workspace/python/pitl/pitl/it/demo/demo_it_n2s_gbm_2D_rgb.py", line 76, in <module>
demo(astronaut())
File "/Users/royer/workspace/python/pitl/pitl/it/demo/demo_it_n2s_gbm_2D_rgb.py", line 31, in demo
rescale_intensity(noisy, in_range='image', out_range=(0, 1)), name='noisy'
File "/Users/royer/anaconda3/envs/pitl/lib/python3.7/contextlib.py", line 119, in __exit__
next(self.gen)
File "/Users/royer/anaconda3/envs/pitl/lib/python3.7/site-packages/napari/_qt/event_loop.py", line 31, in gui_qt
app.exec_()
File "/Users/royer/anaconda3/envs/pitl/lib/python3.7/site-packages/vispy/app/backends/_qt.py", line 501, in event
out = super(QtBaseCanvasBackend, self).event(ev)
File "/Users/royer/anaconda3/envs/pitl/lib/python3.7/site-packages/vispy/app/backends/_qt.py", line 818, in paintGL
self._vispy_canvas.events.draw(region=None)
File "/Users/royer/anaconda3/envs/pitl/lib/python3.7/site-packages/vispy/util/event.py", line 455, in __call__
self._invoke_callback(cb, event)
File "/Users/royer/anaconda3/envs/pitl/lib/python3.7/site-packages/vispy/util/event.py", line 475, in _invoke_callback
self, cb_event=(cb, event))
<< caught exception here: >>
File "/Users/royer/anaconda3/envs/pitl/lib/python3.7/site-packages/vispy/util/event.py", line 471, in _invoke_callback
cb(event)
File "/Users/royer/anaconda3/envs/pitl/lib/python3.7/site-packages/vispy/scene/canvas.py", line 217, in on_draw
self._draw_scene()
File "/Users/royer/anaconda3/envs/pitl/lib/python3.7/site-packages/vispy/scene/canvas.py", line 266, in _draw_scene
self.draw_visual(self.scene)
File "/Users/royer/anaconda3/envs/pitl/lib/python3.7/site-packages/vispy/scene/canvas.py", line 304, in draw_visual
node.draw()
File "/Users/royer/anaconda3/envs/pitl/lib/python3.7/site-packages/vispy/scene/visuals.py", line 99, in draw
self._visual_superclass.draw(self)
File "/Users/royer/anaconda3/envs/pitl/lib/python3.7/site-packages/vispy/visuals/visual.py", line 443, in draw
self._vshare.index_buffer)
File "/Users/royer/anaconda3/envs/pitl/lib/python3.7/site-packages/vispy/visuals/shaders/program.py", line 101, in draw
Program.draw(self, *args, **kwargs)
File "/Users/royer/anaconda3/envs/pitl/lib/python3.7/site-packages/vispy/gloo/program.py", line 533, in draw
canvas.context.flush_commands()
File "/Users/royer/anaconda3/envs/pitl/lib/python3.7/site-packages/vispy/gloo/context.py", line 176, in flush_commands
self.glir.flush(self.shared.parser)
File "/Users/royer/anaconda3/envs/pitl/lib/python3.7/site-packages/vispy/gloo/glir.py", line 572, in flush
self._shared.flush(parser)
File "/Users/royer/anaconda3/envs/pitl/lib/python3.7/site-packages/vispy/gloo/glir.py", line 494, in flush
parser.parse(self._filter(self.clear(), parser))
File "/Users/royer/anaconda3/envs/pitl/lib/python3.7/site-packages/vispy/gloo/glir.py", line 819, in parse
self._parse(command)
File "/Users/royer/anaconda3/envs/pitl/lib/python3.7/site-packages/vispy/gloo/glir.py", line 787, in _parse
ob.set_data(*args)
File "/Users/royer/anaconda3/envs/pitl/lib/python3.7/site-packages/vispy/gloo/glir.py", line 1537, in set_data
raise ValueError("Type %r not allowed for texture" % data.dtype)
ValueError: Type dtype('int64') not allowed for texture
ERROR: Invoking <bound method SceneCanvas.on_draw of <SceneCanvas (PySide2) at 0x128724438>> for DrawEvent
WARNING: Error drawing visual <Image at 0x133fde5f8>
ERROR: Invoking <bound method SceneCanvas.on_draw of <SceneCanvas (PySide2) at 0x128724438>> repeat 2

# Fixed code
def _update_thumbnail(self):
    """Update thumbnail with current image data and colormap."""
    if self.dims.ndisplay == 3:
        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.multichannel:
        # 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
        colormapped = self.colormap[1].map(downsampled)
        colormapped = colormapped.reshape(downsampled.shape + (4,))
        colormapped[..., 3] *= self.opacity
    self.thumbnail = colormapped