# Buggy code
def render_missing_spectrum(
    itmdt: Intermediate, plot_width: int, plot_height: int
) -> Figure:
    """
    Render the missing specturm
    """
    mapper, color_bar = create_color_mapper()
    df = itmdt["data"].copy()
    df["column_with_perc"] = df["column"].apply(
        lambda c: fuse_missing_perc(cut_long_name(c), itmdt["missing_percent"][c])
    )

    radius = (df["loc_end"][0] - df["loc_start"][0]) / 2

    if (df["loc_end"] - df["loc_start"]).max() <= 1:
        loc_tooltip = "@loc_start{1}"
    else:
        loc_tooltip = "@loc_start{1}~@loc_end{1}"

    tooltips = [
        ("Column", "@column"),
        ("Loc", loc_tooltip),
        ("Missing%", "@missing_rate{1%}"),
    ]

    x_range = FactorRange(*df["column_with_perc"].unique())
    minimum, maximum = df["location"].min(), df["location"].max()
    y_range = Range1d(maximum + radius, minimum - radius)

    fig = tweak_figure(
        Figure(
            x_range=x_range,
            y_range=y_range,
            plot_width=plot_width,
            plot_height=plot_height,
            x_axis_location="below",
            tools="hover",
            toolbar_location=None,
            tooltips=tooltips,
        )
    )
    fig.xgrid.grid_line_color = None
    fig.ygrid.grid_line_color = None

    fig.rect(
        x="column_with_perc",
        y="location",
        line_width=0,
        width=0.95,
        height=radius * 2,
        source=df,
        fill_color={"field": "missing_rate", "transform": mapper},
        line_color=None,
    )
    fig.add_layout(color_bar, "right")

    return fig


# Traceback (IndexError)
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-50-47c276e219b8> in <module>
----> 1 plot_missing(X)

~\miniconda3\lib\site-packages\dataprep\eda\missing\__init__.py in plot_missing(df, x, y, bins, ncols, ndist_sample, dtype)
63         df, x, y, dtype=dtype, bins=bins, ncols=ncols, ndist_sample=ndist_sample
64     )
---> 65     fig = render_missing(itmdt)
66     return Report(fig)

~\miniconda3\lib\site-packages\dataprep\eda\missing\render.py in render_missing(itmdt, plot_width, plot_height, palette)
61     elif itmdt.visual_type == "missing_spectrum_heatmap":
62         return render_missing_heatmap(
---> 63             itmdt, plot_width, plot_height, palette or BIPALETTE
64         )
65

~\miniconda3\lib\site-packages\dataprep\eda\missing\render.py in render_missing_heatmap(itmdt, plot_width, plot_height, palette)
287     pan_spectrum = Panel(child=fig_spectrum, title="Spectrum")
288     tabs.append(pan_spectrum)
--> 289     fig_heatmap = render_heatmaps_tab(itmdt, plot_width, plot_height, palette)
290     pan_heatmap = Panel(child=fig_heatmap, title="Heatmap")
291     tabs.append(pan_heatmap)

~\miniconda3\lib\site-packages\dataprep\eda\missing\render.py in render_heatmaps_tab(itmdt, plot_width, plot_height, palette)
307         np.triu(np.ones(df.shape)).astype(np.bool)  # pylint: disable=no-member
308     ).T
--> 309     df = df.unstack().reset_index(name="correlation")
310     df = df.rename(columns={"level_0": "x", "level_1": "y"})
311     df = df[df["x"] != df["y"]]

~\miniconda3\lib\site-packages\pandas\core\frame.py in unstack(self, level, fill_value)
6384         from pandas.core.reshape.reshape import unstack
6385
-> 6386         return unstack(self, level, fill_value)
6387
6388     _shared_docs[

~\miniconda3\lib\site-packages\pandas\core\reshape\reshape.py in unstack(obj, level, fill_value)
408             return _unstack_frame(obj, level, fill_value=fill_value)
409         else:
--> 410             return obj.T.stack(dropna=False)
411     else:
412         if is_extension_array_dtype(obj.dtype):

~\miniconda3\lib\site-packages\pandas\core\frame.py in stack(self, level, dropna)
6249             return stack_multiple(self, level, dropna=dropna)
6250         else:
-> 6251             return stack(self, level, dropna=dropna)
6252
6253     def explode(self, column: Union[str, Tuple]) -> "DataFrame":

~\miniconda3\lib\site-packages\pandas\core\reshape\reshape.py in stack(frame, level, dropna)
541         # we concatenate instead.
542         dtypes = list(frame.dtypes.values)
--> 543         dtype = dtypes[0]
544
545         if is_extension_array_dtype(dtype):

IndexError: list index out of range

# Fixed code
def render_missing_spectrum(
    data_spectrum: pd.DataFrame,
    data_total_missing: pd.DataFrame,
    plot_width: int,
    plot_height: int,
) -> Figure:
    """
    Render the missing specturm
    """
    mapper, color_bar = create_color_mapper()
    df = data_spectrum.copy()

    df["column_with_perc"] = df["column"].apply(
        lambda c: fuse_missing_perc(cut_long_name(c), data_total_missing[c])
    )

    radius = (df["loc_end"][0] - df["loc_start"][0]) / 2

    if (df["loc_end"] - df["loc_start"]).max() <= 1:
        loc_tooltip = "@loc_start{1}"
    else:
        loc_tooltip = "@loc_start{1}~@loc_end{1}"

    tooltips = [
        ("Column", "@column"),
        ("Loc", loc_tooltip),
        ("Missing%", "@missing_rate{1%}"),
    ]

    x_range = FactorRange(*df["column_with_perc"].unique())
    minimum, maximum = df["location"].min(), df["location"].max()
    y_range = Range1d(maximum + radius, minimum - radius)

    fig = tweak_figure(
        Figure(
            x_range=x_range,
            y_range=y_range,
            plot_width=plot_width,
            plot_height=plot_height,
            x_axis_location="below",
            tools="hover",
            toolbar_location=None,
            tooltips=tooltips,
        )
    )
    fig.xgrid.grid_line_color = None
    fig.ygrid.grid_line_color = None

    fig.rect(
        x="column_with_perc",
        y="location",
        line_width=0,
        width=0.95,
        height=radius * 2,
        source=df,
        fill_color={"field": "missing_rate", "transform": mapper},
        line_color=None,
    )
    fig.add_layout(color_bar, "right")

    return fig