# Buggy code
def _set_view_slice(self):
    """Set the view given the indices to slice with."""
    nd = self.dims.not_displayed

    if self.multichannel:
        # if multichannel need to keep the final axis fixed during the
        # transpose. The index of the final axis depends on how many
        # axes are displayed.
        order = self.dims.displayed_order + (self.dims.ndisplay,)
    else:
        order = self.dims.displayed_order

    # Slice thumbnail
    indices = np.array(self.dims.indices)
    downsampled = indices[nd] / self.level_downsamples[-1, nd]
    downsampled = np.round(downsampled.astype(float)).astype(int)
    downsampled = np.clip(downsampled, 0, self.level_shapes[-1, nd] - 1)
    indices[nd] = downsampled
    self._data_thumbnail = np.asarray(self.data[-1][tuple(indices)]).transpose(order)

    # Slice currently viewed level
    indices = np.array(self.dims.indices)
    level = self.data_level
    downsampled = indices[nd] / self.level_downsamples[level, nd]
    downsampled = np.round(downsampled.astype(float)).astype(int)
    downsampled = np.clip(downsampled, 0, self.level_shapes[level, nd] - 1)
    indices[nd] = downsampled

    disp_shape = self.level_shapes[level, self.dims.displayed]
    scale = np.ones(self.ndim)
    for d in self.dims.displayed:
        scale[d] = self.level_downsamples[self.data_level][d]
    self._scale = scale
    self.events.scale()

    if np.any(disp_shape > self._max_tile_shape):
        for d in self.dims.displayed:
            indices[d] = slice(
                self._top_left[d],
                self._top_left[d] + self._max_tile_shape,
                1,
            )
        self.translate = self._top_left * self.scale
    else:
        self.translate = [0] * self.ndim

    self._data_view = np.asarray(self.data[level][tuple(indices)]).transpose(order)

    self._update_thumbnail()
    self._update_coordinates()
    self.events.set_data()


# Traceback (ValueError)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-42-5ae500208e78> in <module>
----> 1 napari.view(array)

/Applications/anaconda3/envs/chloe/lib/python3.7/site-packages/napari/view_function.py in view(title, metadata, multichannel, contrast_limits, *images, **named_images)
51             metadata=metadata,
52             multichannel=multichannel,
---> 53             contrast_limits=contrast_limits,
54         )
55     for name, image in named_images.items():

/Applications/anaconda3/envs/chloe/lib/python3.7/site-packages/napari/components/viewer_model.py in add_image(self, data, multichannel, colormap, contrast_limits, interpolation, rendering, name, metadata, scale, translate, opacity, blending, visible)
411             opacity=opacity,
412             blending=blending,
--> 413             visible=visible,
414         )
415         self.add_layer(layer)

/Applications/anaconda3/envs/chloe/lib/python3.7/site-packages/napari/layers/image/image.py in __init__(self, data, multichannel, colormap, contrast_limits, interpolation, rendering, name, metadata, scale, translate, opacity, blending, visible)
174
175         # Trigger generation of view slice and thumbnail
--> 176         self._update_dims()
177
178     @property

/Applications/anaconda3/envs/chloe/lib/python3.7/site-packages/napari/layers/base/base.py in _update_dims(self)
313             self.dims.set_range(i, r)
314
--> 315         self._set_view_slice()
316         self._update_coordinates()
317

/Applications/anaconda3/envs/chloe/lib/python3.7/site-packages/napari/layers/image/image.py in _set_view_slice(self)
333
334         self._data_thumbnail = self._data_view
--> 335         self._update_thumbnail()
336         self._update_coordinates()
337         self.events.set_data()

/Applications/anaconda3/envs/chloe/lib/python3.7/site-packages/napari/layers/image/image.py in _update_thumbnail(self)
392             colormapped = colormapped.reshape(downsampled.shape + (4,))
393             colormapped[..., 3] *= self.opacity
--> 394         self.thumbnail = colormapped
395
396     def get_value(self):

/Applications/anaconda3/envs/chloe/lib/python3.7/site-packages/napari/layers/base/base.py in thumbnail(self, thumbnail)
353             with warnings.catch_warnings():
354                 warnings.simplefilter("ignore")
--> 355                 thumbnail = img_as_ubyte(thumbnail)
356         self._thumbnail = thumbnail
357         self.events.thumbnail()

/Applications/anaconda3/envs/chloe/lib/python3.7/site-packages/skimage/util/dtype.py in img_as_ubyte(image, force_copy)
484
485     """
--> 486     return convert(image, np.uint8, force_copy)
487
488

/Applications/anaconda3/envs/chloe/lib/python3.7/site-packages/skimage/util/dtype.py in convert(image, dtype, force_copy, uniform)
253
254         if np.min(image) < -1.0 or np.max(image) > 1.0:
--> 255             raise ValueError("Images of type float must be between -1 and 1.")
256         # floating point -> integer
257         prec_loss()

ValueError: Images of type float must be between -1 and 1.

# Fixed code
def _set_view_slice(self):
    """Set the view given the indices to slice with."""
    nd = self.dims.not_displayed

    if self.multichannel:
        # if multichannel need to keep the final axis fixed during the
        # transpose. The index of the final axis depends on how many
        # axes are displayed.
        order = self.dims.displayed_order + (self.dims.ndisplay,)
    else:
        order = self.dims.displayed_order

    # Slice thumbnail
    indices = np.array(self.dims.indices)
    downsampled = indices[nd] / self.level_downsamples[-1, nd]
    downsampled = np.round(downsampled.astype(float)).astype(int)
    downsampled = np.clip(downsampled, 0, self.level_shapes[-1, nd] - 1)
    indices[nd] = downsampled

    image = np.asarray(self.data[-1][tuple(indices)]).transpose(order)

    if self.multichannel and image.dtype.kind == "f":
        self._data_thumbnail = np.clip(image, 0, 1)
    else:
        self._data_thumbnail = image

    # Slice currently viewed level
    indices = np.array(self.dims.indices)
    level = self.data_level
    downsampled = indices[nd] / self.level_downsamples[level, nd]
    downsampled = np.round(downsampled.astype(float)).astype(int)
    downsampled = np.clip(downsampled, 0, self.level_shapes[level, nd] - 1)
    indices[nd] = downsampled

    disp_shape = self.level_shapes[level, self.dims.displayed]
    scale = np.ones(self.ndim)
    for d in self.dims.displayed:
        scale[d] = self.level_downsamples[self.data_level][d]
    self._scale = scale
    self.events.scale()

    if np.any(disp_shape > self._max_tile_shape):
        for d in self.dims.displayed:
            indices[d] = slice(
                self._top_left[d],
                self._top_left[d] + self._max_tile_shape,
                1,
            )
        self.translate = self._top_left * self.scale
    else:
        self.translate = [0] * self.ndim

    image = np.asarray(self.data[level][tuple(indices)]).transpose(order)

    if self.multichannel and image.dtype.kind == "f":
        self._data_view = np.clip(image, 0, 1)
    else:
        self._data_view = image

    self._update_thumbnail()
    self._update_coordinates()
    self.events.set_data()