# Buggy code
def qimage_from_array(arr: np.ndarray) -> QImage:
    """
    Create and return an QImage from a (N, M, C) uint8 array where C is 3 for
    RGB and 4 for RGBA channels.

    Parameters
    ----------
    arr: (N, M C) uint8 array

    Returns
    -------
    image: QImage
        An QImage with size (M, N) in ARGB32 format format depending on `C`.
    """
    h, w, c = arr.shape
    if c == 4:
        format = QImage.Format_ARGB32
    elif c == 3:
        format = QImage.Format_RGB32
    else:
        raise ValueError(f"Wrong number of channels (need 3 or 4, got {c}")
    channels = arr.transpose((2, 0, 1))
    img = QImage(w, h, QImage.Format_ARGB32)
    img.fill(Qt.white)
    buffer = img.bits().asarray(w * h * 4)
    view = np.frombuffer(buffer, np.uint32).reshape((h, w))
    if format == QImage.Format_ARGB32:
        view[:, :] = qrgba(*channels)
    elif format == QImage.Format_RGB32:
        view[:, :] = qrgb(*channels)
    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_from_array(arr: np.ndarray) -> QImage:
    """
    Create and return an QImage from a (N, M, C) uint8 array where C is 3 for
    RGB and 4 for RGBA channels.

    Parameters
    ----------
    arr: (N, M C) uint8 array

    Returns
    -------
    image: QImage
        An QImage with size (M, N) in ARGB32 format format depending on `C`.
    """
    h, w, c = arr.shape
    if c == 4:
        format = QImage.Format_ARGB32
    elif c == 3:
        format = QImage.Format_RGB32
    else:
        raise ValueError(f"Wrong number of channels (need 3 or 4, got {c}")
    channels = arr.transpose((2, 0, 1))
    img = QImage(w, h, QImage.Format_ARGB32)
    img.fill(Qt.white)
    if img.size().isEmpty():
        return img
    buffer = img.bits().asarray(w * h * 4)
    view = np.frombuffer(buffer, np.uint32).reshape((h, w))
    if format == QImage.Format_ARGB32:
        view[:, :] = qrgba(*channels)
    elif format == QImage.Format_RGB32:
        view[:, :] = qrgb(*channels)
    return img