# Buggy code
def data(self, data: np.ndarray):
    cur_npoints = len(self._data)
    self._data = data

    # Adjust the size array when the number of points has changed
    if len(data) < cur_npoints:
        # If there are now fewer points, remove the size and colors of the
        # extra ones
        with self.events.set_data.blocker():
            self._edge_color = self.edge_color[: len(data)]
            self._face_color = self.face_color[: len(data)]
            self._size = self._size[: len(data)]

            for k in self.properties:
                self.properties[k] = self.properties[k][: len(data)]

    elif len(data) > cur_npoints:
        # If there are now more points, add the size and colors of the
        # new ones
        with self.events.set_data.blocker():
            adding = len(data) - cur_npoints
            if len(self._size) > 0:
                new_size = copy(self._size[-1])
                for i in self.dims.displayed:
                    new_size[i] = self.current_size
            else:
                # Add the default size, with a value for each dimension
                new_size = np.repeat(self.current_size, self._size.shape[1])
            size = np.repeat([new_size], adding, axis=0)

            for k in self.properties:
                new_property = np.repeat(self.current_properties[k], adding, axis=0)
                self.properties[k] = np.concatenate(
                    (self.properties[k], new_property), axis=0
                )

            # add new edge colors
            if self._edge_color_mode == ColorMode.DIRECT:
                new_edge_colors = np.tile(self._current_edge_color, (adding, 1))
            elif self._edge_color_mode == ColorMode.CYCLE:
                edge_color_property = self.current_properties[
                    self._edge_color_property
                ][0]
                new_edge_colors = np.tile(
                    self.edge_color_cycle_map[edge_color_property],
                    (adding, 1),
                )
            elif self._edge_color_mode == ColorMode.COLORMAP:
                edge_color_property_value = self.current_properties[
                    self._edge_color_property
                ][0]

                ec, _ = map_property(
                    prop=edge_color_property_value,
                    colormap=self.edge_colormap[1],
                    contrast_limits=self._edge_contrast_limits,
                )
                new_edge_colors = np.tile(ec, (adding, 1))
            self._edge_color = np.vstack((self.edge_color, new_edge_colors))

            # add new face colors
            if self._face_color_mode == ColorMode.DIRECT:
                new_face_colors = np.tile(self._current_face_color, (adding, 1))
            elif self._face_color_mode == ColorMode.CYCLE:
                face_color_property_value = self.current_properties[
                    self._face_color_property
                ][0]
                new_face_colors = np.tile(
                    self.face_color_cycle_map[face_color_property_value],
                    (adding, 1),
                )
            elif self._face_color_mode == ColorMode.COLORMAP:
                face_color_property_value = self.current_properties[
                    self._face_color_property
                ][0]

                fc, _ = map_property(
                    prop=face_color_property_value,
                    colormap=self.face_colormap[1],
                    contrast_limits=self._face_contrast_limits,
                )
                new_face_colors = np.tile(fc, (adding, 1))
            self._face_color = np.vstack((self.face_color, new_face_colors))

            self.size = np.concatenate((self._size, size), axis=0)

    self._update_dims()
    self.events.data()


# 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 data(self, data: np.ndarray):
    cur_npoints = len(self._data)
    self._data = data

    # Adjust the size array when the number of points has changed
    if len(data) < cur_npoints:
        # If there are now fewer points, remove the size and colors of the
        # extra ones
        with self.events.set_data.blocker():
            self._edge_color = self.edge_color[: len(data)]
            self._face_color = self.face_color[: len(data)]
            self._size = self._size[: len(data)]

            for k in self.properties:
                self.properties[k] = self.properties[k][: len(data)]

    elif len(data) > cur_npoints:
        # If there are now more points, add the size and colors of the
        # new ones
        with self.events.set_data.blocker():
            adding = len(data) - cur_npoints
            if len(self._size) > 0:
                new_size = copy(self._size[-1])
                for i in self.dims.displayed:
                    new_size[i] = self.current_size
            else:
                # Add the default size, with a value for each dimension
                new_size = np.repeat(self.current_size, self._size.shape[1])
            size = np.repeat([new_size], adding, axis=0)

            for k in self.properties:
                new_property = np.repeat(self.current_properties[k], adding, axis=0)
                self.properties[k] = np.concatenate(
                    (self.properties[k], new_property), axis=0
                )

            # add new edge colors
            if self._edge_color_mode == ColorMode.DIRECT:
                new_edge_colors = np.tile(self._current_edge_color, (adding, 1))
            elif self._edge_color_mode == ColorMode.CYCLE:
                edge_color_property = self.current_properties[
                    self._edge_color_property
                ][0]
                new_edge_colors = np.tile(
                    self.edge_color_cycle_map[edge_color_property],
                    (adding, 1),
                )
            elif self._edge_color_mode == ColorMode.COLORMAP:
                edge_color_property_value = self.current_properties[
                    self._edge_color_property
                ][0]

                ec, _ = map_property(
                    prop=edge_color_property_value,
                    colormap=self.edge_colormap[1],
                    contrast_limits=self._edge_contrast_limits,
                )
                new_edge_colors = np.tile(ec, (adding, 1))
            self._edge_color = np.vstack((self.edge_color, new_edge_colors))

            # add new face colors
            if self._face_color_mode == ColorMode.DIRECT:
                new_face_colors = np.tile(self._current_face_color, (adding, 1))
            elif self._face_color_mode == ColorMode.CYCLE:
                face_color_property_value = self.current_properties[
                    self._face_color_property
                ][0]
                new_face_colors = np.tile(
                    self.face_color_cycle_map[face_color_property_value],
                    (adding, 1),
                )
            elif self._face_color_mode == ColorMode.COLORMAP:
                face_color_property_value = self.current_properties[
                    self._face_color_property
                ][0]

                fc, _ = map_property(
                    prop=face_color_property_value,
                    colormap=self.face_colormap[1],
                    contrast_limits=self._face_contrast_limits,
                )
                new_face_colors = np.tile(fc, (adding, 1))
            self._face_color = np.vstack((self.face_color, new_face_colors))

            self.size = np.concatenate((self._size, size), axis=0)
            self.selected_data = list(np.arange(cur_npoints, len(data)))

    self._update_dims()
    self.events.data()