# Buggy code
def refresh_colors(self, update_color_mapping: bool = True):
    """Calculate and update face and edge colors if using a cycle or color map

    Parameters
    ----------
    update_color_mapping : bool
        If set to True, the function will recalculate the color cycle map
        or colormap (whichever is being used). If set to False, the function
        will use the current color cycle map or color map. For example, if you
        are adding/modifying points and want them to be colored with the same
        mapping as the other points (i.e., the new points shouldn't affect
        the color cycle map or colormap), set update_color_mapping=False.
        Default value is True.
    """
    if self._update_properties:
        if self._face_color_mode == ColorMode.CYCLE:
            face_color_properties = self.properties[self._face_color_property]
            if update_color_mapping:
                self.face_color_cycle_map = {
                    k: c
                    for k, c in zip(
                        np.unique(face_color_properties),
                        self.face_color_cycle,
                    )
                }
            face_colors = np.array(
                [self.face_color_cycle_map[x] for x in face_color_properties]
            )
            self._face_color = face_colors

            self.events.face_color()
            self.events.highlight()
        elif self._face_color_mode == ColorMode.COLORMAP:
            face_color_properties = self.properties[self._face_color_property]
            if update_color_mapping:
                face_colors, contrast_limits = map_property(
                    prop=face_color_properties,
                    colormap=self.face_colormap[1],
                )
                self.face_contrast_limits = contrast_limits
            else:
                face_colors, _ = map_property(
                    prop=face_color_properties,
                    colormap=self.face_colormap[1],
                    contrast_limits=self.face_contrast_limits,
                )
            self._face_color = face_colors

        if self._edge_color_mode == ColorMode.CYCLE:
            edge_color_properties = self.properties[self._edge_color_property]
            if update_color_mapping:
                self.edge_color_cycle_map = {
                    k: c
                    for k, c in zip(
                        np.unique(edge_color_properties),
                        self.edge_color_cycle,
                    )
                }
            edge_colors = np.array(
                [self.edge_color_cycle_map[x] for x in edge_color_properties]
            )
            self._edge_color = edge_colors
        elif self._edge_color_mode == ColorMode.COLORMAP:
            edge_color_properties = self.properties[self._edge_color_property]
            if update_color_mapping:
                edge_colors, contrast_limits = map_property(
                    prop=edge_color_properties,
                    colormap=self.edge_colormap[1],
                )
                self.edge_contrast_limits = contrast_limits
            else:
                edge_colors, _ = map_property(
                    prop=edge_color_properties,
                    colormap=self.edge_colormap[1],
                    contrast_limits=self.edge_contrast_limits,
                )

            self._edge_color = edge_colors
        self.events.face_color()
        self.events.edge_color()
        self.events.highlight()


# Traceback (ValueError)
WARNING: Traceback (most recent call last):
File "/home/hagai/.conda/envs/ncd/lib/python3.7/site-packages/napari/_qt/qt_viewer_buttons.py", line 173, in <lambda>
lambda state=self: self.change_ndisplay(state)
File "/home/hagai/.conda/envs/ncd/lib/python3.7/site-packages/napari/_qt/qt_viewer_buttons.py", line 178, in change_ndisplay
self.viewer.dims.ndisplay = 3
File "/home/hagai/.conda/envs/ncd/lib/python3.7/site-packages/napari/components/dims.py", line 296, in ndisplay
self.events.ndisplay()
File "/home/hagai/.conda/envs/ncd/lib/python3.7/site-packages/napari/utils/event.py", line 508, in __call__
self._invoke_callback(cb, event)
File "/home/hagai/.conda/envs/ncd/lib/python3.7/site-packages/napari/utils/event.py", line 529, in _invoke_callback
cb_event=(cb, event),
File "/home/hagai/.conda/envs/ncd/lib/python3.7/site-packages/napari/utils/event.py", line 523, in _invoke_callback
cb(event)
File "/home/hagai/.conda/envs/ncd/lib/python3.7/site-packages/napari/components/viewer_model.py", line 88, in <lambda>
self.dims.events.ndisplay.connect(lambda e: self._update_layers())
File "/home/hagai/.conda/envs/ncd/lib/python3.7/site-packages/napari/components/viewer_model.py", line 1037, in _update_layers
layer.dims.ndisplay = self.dims.ndisplay
File "/home/hagai/.conda/envs/ncd/lib/python3.7/site-packages/napari/components/dims.py", line 296, in ndisplay
self.events.ndisplay()
File "/home/hagai/.conda/envs/ncd/lib/python3.7/site-packages/napari/utils/event.py", line 508, in __call__
self._invoke_callback(cb, event)
File "/home/hagai/.conda/envs/ncd/lib/python3.7/site-packages/napari/utils/event.py", line 529, in _invoke_callback
cb_event=(cb, event),
File "/home/hagai/.conda/envs/ncd/lib/python3.7/site-packages/napari/utils/event.py", line 523, in _invoke_callback
cb(event)
File "/home/hagai/.conda/envs/ncd/lib/python3.7/site-packages/napari/layers/base/base.py", line 180, in <lambda>
self.dims.events.ndisplay.connect(lambda e: self._update_dims())
File "/home/hagai/.conda/envs/ncd/lib/python3.7/site-packages/napari/layers/base/base.py", line 383, in _update_dims
self.refresh()
File "/home/hagai/.conda/envs/ncd/lib/python3.7/site-packages/napari/layers/base/base.py", line 600, in refresh
self._set_view_slice()
File "/home/hagai/.conda/envs/ncd/lib/python3.7/site-packages/napari/layers/points/points.py", line 654, in _set_view_slice
self._selected_box = self.interaction_box(self._selected_view)
File "/home/hagai/.conda/envs/ncd/lib/python3.7/site-packages/napari/layers/points/points.py", line 480, in interaction_box
data = points_to_squares(data, size)
File "/home/hagai/.conda/envs/ncd/lib/python3.7/site-packages/napari/layers/points/points.py", line 972, in points_to_squares
points + np.sqrt(2) / 2 * np.array([sizes, sizes]).T,
ValueError: operands could not be broadcast together with shapes (1,3) (1,2)
WARNING:vispy:Traceback (most recent call last):
File "/home/hagai/.conda/envs/ncd/lib/python3.7/site-packages/napari/_qt/qt_viewer_buttons.py", line 173, in <lambda>
lambda state=self: self.change_ndisplay(state)
File "/home/hagai/.conda/envs/ncd/lib/python3.7/site-packages/napari/_qt/qt_viewer_buttons.py", line 178, in change_ndisplay
self.viewer.dims.ndisplay = 3
File "/home/hagai/.conda/envs/ncd/lib/python3.7/site-packages/napari/components/dims.py", line 296, in ndisplay
self.events.ndisplay()
File "/home/hagai/.conda/envs/ncd/lib/python3.7/site-packages/napari/utils/event.py", line 508, in __call__
self._invoke_callback(cb, event)
File "/home/hagai/.conda/envs/ncd/lib/python3.7/site-packages/napari/utils/event.py", line 529, in _invoke_callback
cb_event=(cb, event),
File "/home/hagai/.conda/envs/ncd/lib/python3.7/site-packages/napari/utils/event.py", line 523, in _invoke_callback
cb(event)
File "/home/hagai/.conda/envs/ncd/lib/python3.7/site-packages/napari/components/viewer_model.py", line 88, in <lambda>
self.dims.events.ndisplay.connect(lambda e: self._update_layers())
File "/home/hagai/.conda/envs/ncd/lib/python3.7/site-packages/napari/components/viewer_model.py", line 1037, in _update_layers
layer.dims.ndisplay = self.dims.ndisplay
File "/home/hagai/.conda/envs/ncd/lib/python3.7/site-packages/napari/components/dims.py", line 296, in ndisplay
self.events.ndisplay()
File "/home/hagai/.conda/envs/ncd/lib/python3.7/site-packages/napari/utils/event.py", line 508, in __call__
self._invoke_callback(cb, event)
File "/home/hagai/.conda/envs/ncd/lib/python3.7/site-packages/napari/utils/event.py", line 529, in _invoke_callback
cb_event=(cb, event),
File "/home/hagai/.conda/envs/ncd/lib/python3.7/site-packages/napari/utils/event.py", line 523, in _invoke_callback
cb(event)
File "/home/hagai/.conda/envs/ncd/lib/python3.7/site-packages/napari/layers/base/base.py", line 180, in <lambda>
self.dims.events.ndisplay.connect(lambda e: self._update_dims())
File "/home/hagai/.conda/envs/ncd/lib/python3.7/site-packages/napari/layers/base/base.py", line 383, in _update_dims
self.refresh()
File "/home/hagai/.conda/envs/ncd/lib/python3.7/site-packages/napari/layers/base/base.py", line 600, in refresh
self._set_view_slice()
File "/home/hagai/.conda/envs/ncd/lib/python3.7/site-packages/napari/layers/points/points.py", line 654, in _set_view_slice
self._selected_box = self.interaction_box(self._selected_view)
File "/home/hagai/.conda/envs/ncd/lib/python3.7/site-packages/napari/layers/points/points.py", line 480, in interaction_box
data = points_to_squares(data, size)
File "/home/hagai/.conda/envs/ncd/lib/python3.7/site-packages/napari/layers/points/points.py", line 972, in points_to_squares
points + np.sqrt(2) / 2 * np.array([sizes, sizes]).T,
ValueError: operands could not be broadcast together with shapes (1,3) (1,2)

# Fixed code
def refresh_colors(self, update_color_mapping: bool = True):
    """Calculate and update face and edge colors if using a cycle or color map

    Parameters
    ----------
    update_color_mapping : bool
        If set to True, the function will recalculate the color cycle map
        or colormap (whichever is being used). If set to False, the function
        will use the current color cycle map or color map. For example, if you
        are adding/modifying points and want them to be colored with the same
        mapping as the other points (i.e., the new points shouldn't affect
        the color cycle map or colormap), set update_color_mapping=False.
        Default value is True.
    """
    if self._update_properties:
        if self._face_color_mode == ColorMode.CYCLE:
            face_color_properties = self.properties[self._face_color_property]
            if update_color_mapping:
                self.face_color_cycle_map = {
                    k: c
                    for k, c in zip(
                        np.unique(face_color_properties),
                        self.face_color_cycle,
                    )
                }
            face_colors = np.array(
                [self.face_color_cycle_map[x] for x in face_color_properties]
            )
            self._face_color = face_colors

            self.events.face_color()
        elif self._face_color_mode == ColorMode.COLORMAP:
            face_color_properties = self.properties[self._face_color_property]
            if update_color_mapping:
                face_colors, contrast_limits = map_property(
                    prop=face_color_properties,
                    colormap=self.face_colormap[1],
                )
                self.face_contrast_limits = contrast_limits
            else:
                face_colors, _ = map_property(
                    prop=face_color_properties,
                    colormap=self.face_colormap[1],
                    contrast_limits=self.face_contrast_limits,
                )
            self._face_color = face_colors

        if self._edge_color_mode == ColorMode.CYCLE:
            edge_color_properties = self.properties[self._edge_color_property]
            if update_color_mapping:
                self.edge_color_cycle_map = {
                    k: c
                    for k, c in zip(
                        np.unique(edge_color_properties),
                        self.edge_color_cycle,
                    )
                }
            edge_colors = np.array(
                [self.edge_color_cycle_map[x] for x in edge_color_properties]
            )
            self._edge_color = edge_colors
        elif self._edge_color_mode == ColorMode.COLORMAP:
            edge_color_properties = self.properties[self._edge_color_property]
            if update_color_mapping:
                edge_colors, contrast_limits = map_property(
                    prop=edge_color_properties,
                    colormap=self.edge_colormap[1],
                )
                self.edge_contrast_limits = contrast_limits
            else:
                edge_colors, _ = map_property(
                    prop=edge_color_properties,
                    colormap=self.edge_colormap[1],
                    contrast_limits=self.edge_contrast_limits,
                )

            self._edge_color = edge_colors
        self.events.face_color()
        self.events.edge_color()