# Buggy code
def compute_missing(
    # pylint: disable=too-many-arguments
    df: Union[pd.DataFrame, dd.DataFrame],
    x: Optional[str] = None,
    y: Optional[str] = None,
    *,
    bins: int = 30,
    ncols: int = 30,
    ndist_sample: int = 100,
    dtype: Optional[DTypeDef] = None,
) -> Intermediate:
    """
    This function is designed to deal with missing values
    There are three functions: plot_missing(df), plot_missing(df, x)
    plot_missing(df, x, y)

    Parameters
    ----------
    df
        the pandas data_frame for which plots are calculated for each column
    x
        a valid column name of the data frame
    y
        a valid column name of the data frame
    ncols
        The number of columns in the figure
    bins
        The number of rows in the figure
    ndist_sample
        The number of sample points
    dtype: str or DType or dict of str or dict of DType, default None
        Specify Data Types for designated column or all columns.
        E.g.  dtype = {"a": Continuous, "b": "Nominal"} or
        dtype = {"a": Continuous(), "b": "nominal"}
        or dtype = Continuous() or dtype = "Continuous" or dtype = Continuous()
    Examples
    ----------
    >>> from dataprep.eda.missing.computation import plot_missing
    >>> import pandas as pd
    >>> df = pd.read_csv("suicide-rate.csv")
    >>> plot_missing(df, "HDI_for_year")
    >>> plot_missing(df, "HDI_for_year", "population")
    """
    df = to_dask(df)

    # pylint: disable=no-else-raise
    if x is None and y is not None:
        raise ValueError("x cannot be None while y has value")
    elif x is not None and y is None:
        return missing_impact_1vn(df, dtype=dtype, x=x, bins=bins)
    elif x is not None and y is not None:
        return missing_impact_1v1(
            df, dtype=dtype, x=x, y=y, bins=bins, ndist_sample=ndist_sample
        )
    else:
        # return missing_spectrum(df, bins=bins, ncols=ncols)
        return missing_spectrum_tabs(df, bins=bins, ncols=ncols)


# 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 compute_missing(
    # pylint: disable=too-many-arguments
    df: Union[pd.DataFrame, dd.DataFrame],
    x: Optional[str] = None,
    y: Optional[str] = None,
    *,
    bins: int = 30,
    ncols: int = 30,
    ndist_sample: int = 100,
    dtype: Optional[DTypeDef] = None,
) -> Intermediate:
    """
    This function is designed to deal with missing values
    There are three functions: plot_missing(df), plot_missing(df, x)
    plot_missing(df, x, y)

    Parameters
    ----------
    df
        the pandas data_frame for which plots are calculated for each column
    x
        a valid column name of the data frame
    y
        a valid column name of the data frame
    ncols
        The number of columns in the figure
    bins
        The number of rows in the figure
    ndist_sample
        The number of sample points
    dtype: str or DType or dict of str or dict of DType, default None
        Specify Data Types for designated column or all columns.
        E.g.  dtype = {"a": Continuous, "b": "Nominal"} or
        dtype = {"a": Continuous(), "b": "nominal"}
        or dtype = Continuous() or dtype = "Continuous" or dtype = Continuous()

    Examples
    --------
    >>> from dataprep.eda.missing.computation import plot_missing
    >>> import pandas as pd
    >>> df = pd.read_csv("suicide-rate.csv")
    >>> plot_missing(df, "HDI_for_year")
    >>> plot_missing(df, "HDI_for_year", "population")
    """
    df = to_dask(df)

    # pylint: disable=no-else-raise
    if x is None and y is not None:
        raise ValueError("x cannot be None while y has value")
    elif x is not None and y is None:
        return missing_impact_1vn(df, dtype=dtype, x=x, bins=bins)
    elif x is not None and y is not None:
        return missing_impact_1v1(
            df, dtype=dtype, x=x, y=y, bins=bins, ndist_sample=ndist_sample
        )
    else:
        spectrum, total_missing, bars, heatmap = dd.compute(
            *missing_spectrum(df, bins=bins, ncols=ncols),
            missing_bars(df),
            missing_heatmap(df),
        )

        return Intermediate(
            data_total_missing=total_missing,
            data_spectrum=spectrum,
            data_bars=bars,
            data_heatmap=heatmap,
            visual_type="missing_impact",
        )