# Buggy code
def qimage_indexed_from_array(
    arr: np.ndarray, colortable: Sequence[Sequence[int]]
) -> QImage:
    arr = np.asarray(arr, dtype=np.uint8)
    h, w = arr.shape
    colortable = np.asarray(colortable, dtype=np.uint8)
    ncolors, nchannels = colortable.shape
    img = QImage(w, h, QImage.Format_Indexed8)
    img.setColorCount(ncolors)
    if nchannels == 4:
        qrgb_ = qrgba
    elif nchannels == 3:
        qrgb_ = qrgb
    else:
        raise ValueError

    for i, c in enumerate(colortable):
        img.setColor(i, qrgb_(*c))

    buffer = img.bits().asarray(w * h)
    view = np.frombuffer(buffer, np.uint8).reshape((h, w))
    view[:, :] = arr
    return img


# Traceback (AttributeError)
libpng warning: iCCP: known incorrect sRGB profile
QCssParser::parseColorValue: Specified color without alpha value but alpha given: 'rgb 0, 0, 0, 100'
/home/karin/Documents/git/orange-widget-base/orangewidget/widget.py:286: RuntimeWarning: subclassing of widget classes is deprecated and will be disabled in the future.
Extract code from OWGeneSets or explicitly open it.
RuntimeWarning)
/home/karin/Documents/git/orange-widget-base/orangewidget/widget.py:286: RuntimeWarning: subclassing of widget classes is deprecated and will be disabled in the future.
Extract code from OWPreprocess or explicitly open it.
RuntimeWarning)
/home/karin/Documents/git/orange3-bioinformatics/orangecontrib/bioinformatics/ncbi/gene/__init__.py:177: OrangeDeprecationWarning: Direct calls to Table's constructor are deprecated and will be removed. Replace this call with Table.from_list
table = Table(domain, data_x)
/home/karin/Documents/git/orange3/Orange/widgets/settings.py:82: UserWarning: Storing variables as strings in settings is deprecated.
Support for this will be dropped in Orange 3.26.
Change domain_role_hints to store an instance of `Variable`.
"Storing variables as strings in settings is deprecated.\n"
/home/karin/Documents/git/orange3/Orange/widgets/settings.py:82: UserWarning: Storing variables as strings in settings is deprecated.
Support for this will be dropped in Orange 3.26.
Change domain_role_hints to store an instance of `Variable`.
"Storing variables as strings in settings is deprecated.\n"
/home/karin/Documents/git/orange3-bioinformatics/orangecontrib/bioinformatics/ncbi/gene/__init__.py:177: OrangeDeprecationWarning: Direct calls to Table's constructor are deprecated and will be removed. Replace this call with Table.from_list
table = Table(domain, data_x)
/home/karin/Documents/git/orange3venv/lib/python3.6/site-packages/orangecontrib/prototypes/widgets/owunique.py:87: OrangeDeprecationWarning: Call to deprecated <function Domain.__iter__ at 0x7f581ae761e0>; Instead, use Domain.variables
self.model_attrs = (list(data.domain) + list(data.domain.metas), [])
ERROR:orangewidget.workflow.widgetsscheme:Error calling 'set_dataset' of 'Heat Map (1)'
Traceback (most recent call last):
File "/home/karin/Documents/git/orange-widget-base/orangewidget/workflow/widgetsscheme.py", line 826, in process_signals_for_widget
handler(*args)
File "/home/karin/Documents/git/orange3/Orange/widgets/visualize/owheatmap.py", line 557, in set_dataset
self.update_heatmaps()
File "/home/karin/Documents/git/orange3/Orange/widgets/visualize/owheatmap.py", line 589, in update_heatmaps
self.construct_heatmaps_scene(parts, self.effective_data)
File "/home/karin/Documents/git/orange3/Orange/widgets/visualize/owheatmap.py", line 773, in construct_heatmaps_scene
self.setup_scene(parts, data)
File "/home/karin/Documents/git/orange3/Orange/widgets/visualize/owheatmap.py", line 796, in setup_scene
widget.setHeatmaps(parts)
File "/home/karin/Documents/git/orange3/Orange/widgets/visualize/utils/heatmap.py", line 450, in setHeatmaps
data=X_part, span=parts.span, colormap=colormap,
File "/home/karin/Documents/git/orange3/Orange/widgets/visualize/utils/heatmap.py", line 953, in __init__
self.setHeatmapData(data)
File "/home/karin/Documents/git/orange3/Orange/widgets/visualize/utils/heatmap.py", line 987, in setHeatmapData
self.__updatePixmap()
File "/home/karin/Documents/git/orange3/Orange/widgets/visualize/utils/heatmap.py", line 1020, in __updatePixmap
qimage = qimage_from_array(rgb)
File "/home/karin/Documents/git/orange3/Orange/widgets/utils/image.py", line 33, in qimage_from_array
buffer = img.bits().asarray(w * h * 4)
AttributeError: 'NoneType' object has no attribute 'asarray'
-------------------------- AttributeError Exception ---------------------------
Traceback (most recent call last):
File "/home/karin/Documents/git/orange3venv/lib/python3.6/site-packages/orangecanvas/scheme/signalmanager.py", line 936, in __process_next
if self.__process_next_helper(use_max_active=True):
File "/home/karin/Documents/git/orange3venv/lib/python3.6/site-packages/orangecanvas/scheme/signalmanager.py", line 974, in __process_next_helper
self.process_node(selected_node)
File "/home/karin/Documents/git/orange3venv/lib/python3.6/site-packages/orangecanvas/scheme/signalmanager.py", line 605, in process_node
self.send_to_node(node, signals_in)
File "/home/karin/Documents/git/orange-widget-base/orangewidget/workflow/widgetsscheme.py", line 792, in send_to_node
self.process_signals_for_widget(node, widget, signals)
File "/home/karin/Documents/git/orange-widget-base/orangewidget/workflow/widgetsscheme.py", line 826, in process_signals_for_widget
handler(*args)
File "/home/karin/Documents/git/orange3/Orange/widgets/visualize/owheatmap.py", line 557, in set_dataset
self.update_heatmaps()
File "/home/karin/Documents/git/orange3/Orange/widgets/visualize/owheatmap.py", line 589, in update_heatmaps
self.construct_heatmaps_scene(parts, self.effective_data)
File "/home/karin/Documents/git/orange3/Orange/widgets/visualize/owheatmap.py", line 773, in construct_heatmaps_scene
self.setup_scene(parts, data)
File "/home/karin/Documents/git/orange3/Orange/widgets/visualize/owheatmap.py", line 796, in setup_scene
widget.setHeatmaps(parts)
File "/home/karin/Documents/git/orange3/Orange/widgets/visualize/utils/heatmap.py", line 450, in setHeatmaps
data=X_part, span=parts.span, colormap=colormap,
File "/home/karin/Documents/git/orange3/Orange/widgets/visualize/utils/heatmap.py", line 953, in __init__
self.setHeatmapData(data)
File "/home/karin/Documents/git/orange3/Orange/widgets/visualize/utils/heatmap.py", line 987, in setHeatmapData
self.__updatePixmap()
File "/home/karin/Documents/git/orange3/Orange/widgets/visualize/utils/heatmap.py", line 1020, in __updatePixmap
qimage = qimage_from_array(rgb)
File "/home/karin/Documents/git/orange3/Orange/widgets/utils/image.py", line 33, in qimage_from_array
buffer = img.bits().asarray(w * h * 4)
AttributeError: 'NoneType' object has no attribute 'asarray'
-------------------------------------------------------------------------------
QLayout: Attempting to add QLayout "" to ErrorReporting "", which already has a layout
Segmentation fault (core dumped)

# Fixed code
def qimage_indexed_from_array(
    arr: np.ndarray, colortable: Sequence[Sequence[int]]
) -> QImage:
    arr = np.asarray(arr, dtype=np.uint8)
    h, w = arr.shape
    colortable = np.asarray(colortable, dtype=np.uint8)
    ncolors, nchannels = colortable.shape
    img = QImage(w, h, QImage.Format_Indexed8)
    img.setColorCount(ncolors)
    if nchannels == 4:
        qrgb_ = qrgba
    elif nchannels == 3:
        qrgb_ = qrgb
    else:
        raise ValueError

    for i, c in enumerate(colortable):
        img.setColor(i, qrgb_(*c))
    if img.size().isEmpty():
        return img
    buffer = img.bits().asarray(w * h)
    view = np.frombuffer(buffer, np.uint8).reshape((h, w))
    view[:, :] = arr
    return img