# Buggy code
def __init__(
    self, data, format="%.6g", xlabels=None, ylabels=None, readonly=False, parent=None
):
    QAbstractTableModel.__init__(self)

    self.dialog = parent
    self.changes = {}
    self.xlabels = xlabels
    self.ylabels = ylabels
    self.readonly = readonly
    self.test_array = np.array([0], dtype=data.dtype)

    # for complex numbers, shading will be based on absolute value
    # but for all other types it will be the real part
    if data.dtype in (np.complex64, np.complex128):
        self.color_func = np.abs
    else:
        self.color_func = np.real

    # Backgroundcolor settings
    huerange = [0.66, 0.99]  # Hue
    self.sat = 0.7  # Saturation
    self.val = 1.0  # Value
    self.alp = 0.6  # Alpha-channel

    self._data = data
    self._format = format

    self.total_rows = self._data.shape[0]
    self.total_cols = self._data.shape[1]
    size = self.total_rows * self.total_cols

    try:
        self.vmin = np.nanmin(self.color_func(data))
        self.vmax = np.nanmax(self.color_func(data))
        if self.vmax == self.vmin:
            self.vmin -= 1
        self.hue0 = huerange[0]
        self.dhue = huerange[1] - huerange[0]
        self.bgcolor_enabled = True
    except (TypeError, ValueError):
        self.vmin = None
        self.vmax = None
        self.hue0 = None
        self.dhue = None
        self.bgcolor_enabled = False

    # Array with infinite values cannot display background colors and
    # crashes. See: spyder-ide/spyder#8093
    self.has_inf = np.inf in data

    # Deactivate coloring for object arrays or arrays with inf values
    if self._data.dtype.name == "object" or self.has_inf:
        self.bgcolor_enabled = False

    # Use paging when the total size, number of rows or number of
    # columns is too large
    if size > LARGE_SIZE:
        self.rows_loaded = self.ROWS_TO_LOAD
        self.cols_loaded = self.COLS_TO_LOAD
    else:
        if self.total_rows > LARGE_NROWS:
            self.rows_loaded = self.ROWS_TO_LOAD
        else:
            self.rows_loaded = self.total_rows
        if self.total_cols > LARGE_COLS:
            self.cols_loaded = self.COLS_TO_LOAD
        else:
            self.cols_loaded = self.total_cols


# Traceback (AttributeError)
File "/Users/hilaryc/opt/anaconda3/envs/seis/lib/python3.7/site-packages/spyder/plugins/variableexplorer/widgets/collectionsdelegate.py", line 138, in createEditor
if not editor.setup_and_check(value, title=key, readonly=readonly):
File "/Users/hilaryc/opt/anaconda3/envs/seis/lib/python3.7/site-packages/spyder/plugins/variableexplorer/widgets/arrayeditor.py", line 699, in setup_and_check
ylabels))
File "/Users/hilaryc/opt/anaconda3/envs/seis/lib/python3.7/site-packages/spyder/plugins/variableexplorer/widgets/arrayeditor.py", line 568, in __init__
ylabels=ylabels, readonly=readonly, parent=self)
File "/Users/hilaryc/opt/anaconda3/envs/seis/lib/python3.7/site-packages/spyder/plugins/variableexplorer/widgets/arrayeditor.py", line 156, in __init__
self.vmin = np.nanmin(self.color_func(data))
File "<__array_function__ internals>", line 6, in nanmin
File "/Users/hilaryc/opt/anaconda3/envs/seis/lib/python3.7/site-packages/numpy/lib/nanfunctions.py", line 334, in nanmin
res = _copyto(res, np.nan, mask)
File "/Users/hilaryc/opt/anaconda3/envs/seis/lib/python3.7/site-packages/numpy/lib/nanfunctions.py", line 139, in _copyto
a = a.dtype.type(val)
AttributeError: 'float' object has no attribute 'dtype'
Traceback (most recent call last):
File "/Users/hilaryc/opt/anaconda3/envs/seis/lib/python3.7/site-packages/spyder/plugins/variableexplorer/widgets/collectionsdelegate.py", line 138, in createEditor
if not editor.setup_and_check(value, title=key, readonly=readonly):
File "/Users/hilaryc/opt/anaconda3/envs/seis/lib/python3.7/site-packages/spyder/plugins/variableexplorer/widgets/arrayeditor.py", line 699, in setup_and_check
ylabels))
File "/Users/hilaryc/opt/anaconda3/envs/seis/lib/python3.7/site-packages/spyder/plugins/variableexplorer/widgets/arrayeditor.py", line 568, in __init__
ylabels=ylabels, readonly=readonly, parent=self)
File "/Users/hilaryc/opt/anaconda3/envs/seis/lib/python3.7/site-packages/spyder/plugins/variableexplorer/widgets/arrayeditor.py", line 156, in __init__
self.vmin = np.nanmin(self.color_func(data))
File "<__array_function__ internals>", line 6, in nanmin
File "/Users/hilaryc/opt/anaconda3/envs/seis/lib/python3.7/site-packages/numpy/lib/nanfunctions.py", line 334, in nanmin
res = _copyto(res, np.nan, mask)
File "/Users/hilaryc/opt/anaconda3/envs/seis/lib/python3.7/site-packages/numpy/lib/nanfunctions.py", line 139, in _copyto
a = a.dtype.type(val)
AttributeError: 'float' object has no attribute 'dtype'

# Fixed code
def __init__(
    self, data, format="%.6g", xlabels=None, ylabels=None, readonly=False, parent=None
):
    QAbstractTableModel.__init__(self)

    self.dialog = parent
    self.changes = {}
    self.xlabels = xlabels
    self.ylabels = ylabels
    self.readonly = readonly
    self.test_array = np.array([0], dtype=data.dtype)

    # for complex numbers, shading will be based on absolute value
    # but for all other types it will be the real part
    if data.dtype in (np.complex64, np.complex128):
        self.color_func = np.abs
    else:
        self.color_func = np.real

    # Backgroundcolor settings
    huerange = [0.66, 0.99]  # Hue
    self.sat = 0.7  # Saturation
    self.val = 1.0  # Value
    self.alp = 0.6  # Alpha-channel

    self._data = data
    self._format = format

    self.total_rows = self._data.shape[0]
    self.total_cols = self._data.shape[1]
    size = self.total_rows * self.total_cols

    try:
        self.vmin = np.nanmin(self.color_func(data))
        self.vmax = np.nanmax(self.color_func(data))
        if self.vmax == self.vmin:
            self.vmin -= 1
        self.hue0 = huerange[0]
        self.dhue = huerange[1] - huerange[0]
        self.bgcolor_enabled = True
    except (AttributeError, TypeError, ValueError):
        self.vmin = None
        self.vmax = None
        self.hue0 = None
        self.dhue = None
        self.bgcolor_enabled = False

    # Array with infinite values cannot display background colors and
    # crashes. See: spyder-ide/spyder#8093
    self.has_inf = np.inf in data

    # Deactivate coloring for object arrays or arrays with inf values
    if self._data.dtype.name == "object" or self.has_inf:
        self.bgcolor_enabled = False

    # Use paging when the total size, number of rows or number of
    # columns is too large
    if size > LARGE_SIZE:
        self.rows_loaded = self.ROWS_TO_LOAD
        self.cols_loaded = self.COLS_TO_LOAD
    else:
        if self.total_rows > LARGE_NROWS:
            self.rows_loaded = self.ROWS_TO_LOAD
        else:
            self.rows_loaded = self.total_rows
        if self.total_cols > LARGE_COLS:
            self.cols_loaded = self.COLS_TO_LOAD
        else:
            self.cols_loaded = self.total_cols