# Buggy code
def _determine_cmap_params(self, plot_data, vmin, vmax, cmap, center, robust):
    """Use some heuristics to set good defaults for colorbar and range."""

    # plot_data is a np.ma.array instance
    calc_data = plot_data.filled(np.nan)
    if vmin is None:
        if robust:
            vmin = np.nanpercentile(calc_data, 2)
        else:
            vmin = np.nanmin(calc_data)
    if vmax is None:
        if robust:
            vmax = np.nanpercentile(calc_data, 98)
        else:
            vmax = np.nanmax(calc_data)
    self.vmin, self.vmax = vmin, vmax

    # Choose default colormaps if not provided
    if cmap is None:
        if center is None:
            self.cmap = cm.rocket
        else:
            self.cmap = cm.icefire
    elif isinstance(cmap, str):
        self.cmap = mpl.cm.get_cmap(cmap)
    elif isinstance(cmap, list):
        self.cmap = mpl.colors.ListedColormap(cmap)
    else:
        self.cmap = cmap

    # Recenter a divergent colormap
    if center is not None:
        # Copy bad values
        # in mpl<3.2 only masked values are honored with "bad" color spec
        # (see https://github.com/matplotlib/matplotlib/pull/14257)
        bad = self.cmap(np.ma.masked_invalid([np.nan]))[0]

        # under/over values are set for sure when cmap extremes
        # do not map to the same color as +-inf
        under = self.cmap(-np.inf)
        over = self.cmap(np.inf)
        under_set = under != self.cmap(0)
        over_set = over != self.cmap(self.cmap.N - 1)

        vrange = max(vmax - center, center - vmin)
        normlize = mpl.colors.Normalize(center - vrange, center + vrange)
        cmin, cmax = normlize([vmin, vmax])
        cc = np.linspace(cmin, cmax, 256)
        self.cmap = mpl.colors.ListedColormap(self.cmap(cc))
        self.cmap.set_bad(bad)
        if under_set:
            self.cmap.set_under(under)
        if over_set:
            self.cmap.set_over(over)


# Traceback (ValueError)
---------------------------------------------------------------------------

ValueError                                Traceback (most recent call last)

~.../venv_mac/lib/python3.8/site-packages/numpy/ma/core.py in _check_fill_value(fill_value, ndtype)
472             try:
--> 473                 fill_value = np.array(fill_value, copy=False, dtype=ndtype)
474             except (OverflowError, ValueError):

ValueError: cannot convert float NaN to integer


During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)

<ipython-input-61-c14fb3f470ab> in <module>
1 with sns.axes_style("white"):
2     f, ax = plt.subplots(figsize=(7, 5))
----> 3     ax = sns.heatmap(numbers, mask=mask)
4     # ax = sns.heatmap(numbers)
5

~.../venv_mac/lib/python3.8/site-packages/seaborn/matrix.py in heatmap(data, vmin, vmax, cmap, center, robust, annot, fmt, annot_kws, linewidths, linecolor, cbar, cbar_kws, cbar_ax, square, xticklabels, yticklabels, mask, ax, **kwargs)
533     """
534     # Initialize the plotter object
--> 535     plotter = _HeatMapper(data, vmin, vmax, cmap, center, robust, annot, fmt,
536                           annot_kws, cbar, cbar_kws, xticklabels,
537                           yticklabels, mask)

~.../venv_mac/lib/python3.8/site-packages/seaborn/matrix.py in __init__(self, data, vmin, vmax, cmap, center, robust, annot, fmt, annot_kws, cbar, cbar_kws, xticklabels, yticklabels, mask)
162
163         # Determine good default values for the colormapping
--> 164         self._determine_cmap_params(plot_data, vmin, vmax,
165                                     cmap, center, robust)
166

~.../venv_mac/lib/python3.8/site-packages/seaborn/matrix.py in _determine_cmap_params(self, plot_data, vmin, vmax, cmap, center, robust)
196
197         # plot_data is a np.ma.array instance
--> 198         calc_data = plot_data.filled(np.nan)
199         if vmin is None:
200             if robust:

~.../venv_mac/lib/python3.8/site-packages/numpy/ma/core.py in filled(self, fill_value)
3737             fill_value = self.fill_value
3738         else:
-> 3739             fill_value = _check_fill_value(fill_value, self.dtype)
3740
3741         if self is masked_singleton:

~.../venv_mac/lib/python3.8/site-packages/numpy/ma/core.py in _check_fill_value(fill_value, ndtype)
477                 # that the passed fill_value is not compatible with the ndtype.
478                 err_msg = "Cannot convert fill_value %s to dtype %s"
--> 479                 raise TypeError(err_msg % (fill_value, ndtype))
480     return np.array(fill_value)
481

TypeError: Cannot convert fill_value nan to dtype int64

# Fixed code
def _determine_cmap_params(self, plot_data, vmin, vmax, cmap, center, robust):
    """Use some heuristics to set good defaults for colorbar and range."""

    # plot_data is a np.ma.array instance
    calc_data = plot_data.astype(np.float).filled(np.nan)
    if vmin is None:
        if robust:
            vmin = np.nanpercentile(calc_data, 2)
        else:
            vmin = np.nanmin(calc_data)
    if vmax is None:
        if robust:
            vmax = np.nanpercentile(calc_data, 98)
        else:
            vmax = np.nanmax(calc_data)
    self.vmin, self.vmax = vmin, vmax

    # Choose default colormaps if not provided
    if cmap is None:
        if center is None:
            self.cmap = cm.rocket
        else:
            self.cmap = cm.icefire
    elif isinstance(cmap, str):
        self.cmap = mpl.cm.get_cmap(cmap)
    elif isinstance(cmap, list):
        self.cmap = mpl.colors.ListedColormap(cmap)
    else:
        self.cmap = cmap

    # Recenter a divergent colormap
    if center is not None:
        # Copy bad values
        # in mpl<3.2 only masked values are honored with "bad" color spec
        # (see https://github.com/matplotlib/matplotlib/pull/14257)
        bad = self.cmap(np.ma.masked_invalid([np.nan]))[0]

        # under/over values are set for sure when cmap extremes
        # do not map to the same color as +-inf
        under = self.cmap(-np.inf)
        over = self.cmap(np.inf)
        under_set = under != self.cmap(0)
        over_set = over != self.cmap(self.cmap.N - 1)

        vrange = max(vmax - center, center - vmin)
        normlize = mpl.colors.Normalize(center - vrange, center + vrange)
        cmin, cmax = normlize([vmin, vmax])
        cc = np.linspace(cmin, cmax, 256)
        self.cmap = mpl.colors.ListedColormap(self.cmap(cc))
        self.cmap.set_bad(bad)
        if under_set:
            self.cmap.set_under(under)
        if over_set:
            self.cmap.set_over(over)