# Buggy code
def data(self, data: Union[list, np.ndarray]):
    """set the vertex data and build the vispy arrays for display"""

    # convert data to a numpy array if it is not already one
    data = np.asarray(data)

    # Sort data by ID then time
    self._order = np.lexsort((data[:, 1], data[:, 0]))
    data = data[self._order]

    # check check the formatting of the incoming track data
    self._data = self._validate_track_data(data)

    # build the indices for sorting points by time
    self._ordered_points_idx = np.argsort(self.data[:, 1])
    self._points = self.data[self._ordered_points_idx, 1:]

    # build a tree of the track data to allow fast lookup of nearest track
    self._kdtree = cKDTree(self._points)

    # make the lookup table
    # NOTE(arl): it's important to convert the time index to an integer
    # here to make sure that we align with the napari dims index which
    # will be an integer - however, the time index does not necessarily
    # need to be an int, and the shader will render correctly.
    frames = list(set(self._points[:, 0].astype(np.uint).tolist()))
    self._points_lookup = [None] * (max(frames) + 1)
    for f in frames:
        idx = np.where(self._points[:, 0] == f)[0]
        self._points_lookup[f] = slice(min(idx), max(idx) + 1, 1)

    # make a second lookup table using a sparse matrix to convert track id
    # to the vertex indices
    self._id2idxs = coo_matrix(
        (
            np.broadcast_to(1, self.track_ids.size),  # just dummy ones
            (self.track_ids, np.arange(self.track_ids.size)),
        )
    ).tocsr()


# Traceback (ValueError)
ERROR:root:Unhandled exception:
Traceback (most recent call last):
File "/home/kapoorlab/anaconda3/envs/tensorflowGPU/lib/python3.8/site-packages/napari/_qt/event_loop.py", line 79, in gui_qt
yield app
File "<ipython-input-2-498e4844dd1f>", line 9, in <module>
Tracks = napari.view_tracks(tracks_data,name='tracks')
File "/home/kapoorlab/anaconda3/envs/tensorflowGPU/lib/python3.8/site-packages/napari/view_layers.py", line 9, in view_tracks
(where <layer_type> is replaced with one of the layer types):
File "<string>", line 3, in add_tracks
File "/home/kapoorlab/anaconda3/envs/tensorflowGPU/lib/python3.8/site-packages/napari/components/add_layers_mixin.py", line 72, in add_layer
self.layers.append(layer)
File "/home/kapoorlab/anaconda3/envs/tensorflowGPU/lib/python3.8/site-packages/napari/utils/list/_model.py", line 59, in append
self.events.added(item=obj, index=len(self) - 1)
File "/home/kapoorlab/anaconda3/envs/tensorflowGPU/lib/python3.8/site-packages/napari/utils/events/event.py", line 514, in __call__
self._invoke_callback(cb, event)
File "/home/kapoorlab/anaconda3/envs/tensorflowGPU/lib/python3.8/site-packages/napari/utils/events/event.py", line 531, in _invoke_callback
_handle_exception(
File "/home/kapoorlab/anaconda3/envs/tensorflowGPU/lib/python3.8/site-packages/napari/utils/events/event.py", line 529, in _invoke_callback
cb(event)
File "/home/kapoorlab/anaconda3/envs/tensorflowGPU/lib/python3.8/site-packages/napari/_qt/qt_viewer.py", line 323, in _add_layer
vispy_layer = create_vispy_visual(layer)
File "/home/kapoorlab/anaconda3/envs/tensorflowGPU/lib/python3.8/site-packages/napari/_vispy/utils.py", line 44, in create_vispy_visual
return visual(layer)
File "/home/kapoorlab/anaconda3/envs/tensorflowGPU/lib/python3.8/site-packages/napari/_vispy/vispy_tracks_layer.py", line 50, in __init__
self._on_data_change()
File "/home/kapoorlab/anaconda3/envs/tensorflowGPU/lib/python3.8/site-packages/napari/_vispy/vispy_tracks_layer.py", line 62, in _on_data_change
labels_text, labels_pos = self.layer.track_labels
File "/home/kapoorlab/anaconda3/envs/tensorflowGPU/lib/python3.8/site-packages/napari/layers/tracks/tracks.py", line 543, in track_labels
padded_positions = self._pad_display_data(positions)
File "/home/kapoorlab/anaconda3/envs/tensorflowGPU/lib/python3.8/site-packages/napari/layers/tracks/tracks.py", line 306, in _pad_display_data
data = np.pad(data, ((0, 0), (0, 1)), 'constant')
File "<__array_function__ internals>", line 5, in pad
File "/home/kapoorlab/anaconda3/envs/tensorflowGPU/lib/python3.8/site-packages/numpy/lib/arraypad.py", line 748, in pad
pad_width = _as_pairs(pad_width, array.ndim, as_index=True)
File "/home/kapoorlab/anaconda3/envs/tensorflowGPU/lib/python3.8/site-packages/numpy/lib/arraypad.py", line 523, in _as_pairs
return np.broadcast_to(x, (ndim, 2)).tolist()
File "<__array_function__ internals>", line 5, in broadcast_to
File "/home/kapoorlab/anaconda3/envs/tensorflowGPU/lib/python3.8/site-packages/numpy/lib/stride_tricks.py", line 182, in broadcast_to
return _broadcast_to(array, shape, subok=subok, readonly=True)
File "/home/kapoorlab/anaconda3/envs/tensorflowGPU/lib/python3.8/site-packages/numpy/lib/stride_tricks.py", line 125, in _broadcast_to
it = np.nditer(
ValueError: operands could not be broadcast together with remapped shapes [original->remapped]: (2,2) and requested shape (3,2)

# Fixed code
def data(self, data: Union[list, np.ndarray]):
    """set the vertex data and build the vispy arrays for display"""

    # convert data to a numpy array if it is not already one
    data = np.asarray(data)

    # Sort data by ID then time
    self._order = np.lexsort((data[:, 1], data[:, 0]))
    data = data[self._order]

    # check check the formatting of the incoming track data
    self._data = self._validate_track_data(data)

    # build the indices for sorting points by time
    self._ordered_points_idx = np.argsort(self.data[:, 1])
    self._points = self.data[self._ordered_points_idx, 1:]

    # build a tree of the track data to allow fast lookup of nearest track
    self._kdtree = cKDTree(self._points)

    # make the lookup table
    # NOTE(arl): it's important to convert the time index to an integer
    # here to make sure that we align with the napari dims index which
    # will be an integer - however, the time index does not necessarily
    # need to be an int, and the shader will render correctly.
    frames = list(set(self._points[:, 0].astype(np.uint).tolist()))
    self._points_lookup = {}
    for f in frames:
        idx = np.where(self._points[:, 0] == f)[0]
        self._points_lookup[f] = slice(min(idx), max(idx) + 1, 1)

    # make a second lookup table using a sparse matrix to convert track id
    # to the vertex indices
    self._id2idxs = coo_matrix(
        (
            np.broadcast_to(1, self.track_ids.size),  # just dummy ones
            (self.track_ids, np.arange(self.track_ids.size)),
        )
    ).tocsr()