# Buggy code
def _on_data_change(self):
    if self.layer.dims.ndisplay == 3:
        self.node.set_data(
            self.layer._data_view,
            contrast_limits=self.layer.contrast_limits,
        )
    else:
        self.node._need_colortransform_update = True
        self.node.set_data(self.layer._data_view)
    self.node.update()


# 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 _on_data_change(self):
    data = self.layer._data_view
    dtype = np.dtype(data.dtype)
    if dtype not in texture_dtypes:
        try:
            dtype = dict(i=np.int16, f=np.float32)[dtype.kind]
        except KeyError:  # not an int or float
            raise TypeError(
                f"type {dtype} not allowed for texture; must be one of {set(texture_dtypes)}"
            )
        data = data.astype(dtype)

    if self.layer.dims.ndisplay == 3:
        self.node.set_data(data, clim=self.layer.contrast_limits)
    else:
        self.node._need_colortransform_update = True
        self.node.set_data(data)
    self.node.update()