# Buggy code
def stats_viz_cat(
    data: Tuple[Dict[str, str], Dict[str, str], Dict[str, str], Dict[str, str]],
    plot_width: int,
    plot_height: int,
) -> Panel:
    """
    Render statistics panel for categorical data
    """
    # pylint: disable=line-too-long
    ov_content = ""
    lens_content = ""
    qs_content = ""
    ls_content = ""
    for key, value in data[0].items():
        value = _sci_notation_superscript(value)
        if "Distinct" in key and float(value) > 50:
            ov_content += _create_table_row(key, value, True)
        elif "Unique" in key and float(value.replace("%", "")) == 100:
            ov_content += _create_table_row(key, value, True)
        elif "Missing" in key and float(value.replace("%", "")) != 0:
            ov_content += _create_table_row(key, value, True)
        else:
            ov_content += _create_table_row(key, value)
    for key, value in data[1].items():
        lens_content += _create_table_row(key, value)
    for key, value in data[2].items():
        qs_content += _create_table_row(key, value)
    for key, value in data[3].items():
        ls_content += _create_table_row(key, value)

    ov_content = f"""
    <div style="grid-area: a;">
        <h3 style="text-align: center;">Overview</h3>
        <table style="width: 100%; table-layout: auto;">
            <tbody>{ov_content}</tbody>
        </table>
    </div>
    """
    lens_content = f"""
    <div style="grid-area: b;">
        <h3 style="text-align: center;">Length</h3>
        <table style="width: 100%; table-layout: auto; font-size:11px;">
            <tbody>{lens_content}</tbody>
        </table>
    </div>
    """
    qs_content = f"""
    <div style="grid-area: c;">
        <h3 style="text-align: center;margin-top: -10px;">Quantile Statistics</h3>
        <table style="width: 100%; table-layout: auto; font-size:11px;">
            <tbody>{qs_content}</tbody>
        </table>
    </div>
    """
    ls_content = f"""
    <div style="grid-area: d;">
        <h3 style="text-align: center;margin-top: -10px;">Letter</h3>
        <table style="width: 100%; table-layout: auto; font-size:11px;">
            <tbody>{ls_content}</tbody>
        </table>
    </div>
    """
    container = f"""<div style="display: grid;grid-template-columns: 1fr 1fr;grid-template-rows: 1fr 1fr;gap: 1px 1px;
                grid-template-areas:\'a b\' \'c d\';">
                {ov_content}{lens_content}{qs_content}{ls_content}</div>"""

    div = Div(
        text=container, width=plot_width, height=plot_height, style={"width": "100%"}
    )
    return Panel(child=div, title="stats")


# Traceback (ValueError)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-43-f8a3846cc211> in <module>
1 df = pd.DataFrame({"A": ["01-02", "01-02"]})
----> 2 plot(df, "A", top_words=2)

~/dataprep/dataprep/eda/basic/__init__.py in plot(df, x, y, z, bins, ngroups, largest, nsubgroups, timeunit, agg, sample_size, value_range, yscale, tile_size, dtype, top_words, stopword, lemmatize, stem)
163         stem=stem,
164     )
--> 165     figure = render(intermediate, yscale=yscale, tile_size=tile_size)
166
167     return Report(figure)

~/dataprep/dataprep/eda/basic/render.py in render(itmdt, yscale, tile_size, plot_width_sml, plot_height_sml, plot_width_lrg, plot_height_lrg, plot_width_wide)
1684         visual_elem = render_basic(itmdt, yscale, plot_width_sml, plot_height_sml)
1685     elif itmdt.visual_type == "categorical_column":
-> 1686         visual_elem = render_cat(itmdt, yscale, plot_width_lrg, plot_height_lrg)
1687     elif itmdt.visual_type == "numerical_column":
1688         visual_elem = render_num(itmdt, yscale, plot_width_lrg, plot_height_lrg)

~/dataprep/dataprep/eda/basic/render.py in render_cat(itmdt, yscale, plot_width, plot_height)
1393     tabs.append(pie_viz(df, itmdt["col"], miss_pct, plot_width, plot_height))
1394     freq_tuple = itmdt["word_cloud"]
-> 1395     word_cloud = wordcloud_viz(freq_tuple, plot_width, plot_height)
1396     tabs.append(Panel(child=row(word_cloud), title="word cloud"))
1397     wordfreq = wordfreq_viz(freq_tuple, plot_width, plot_height, True)

~/dataprep/dataprep/eda/basic/render.py in wordcloud_viz(freq_tuple, plot_width, plot_height)
228     )
229     top_freq = freq_tuple[1]
--> 230     wordcloud.generate_from_frequencies(dict(top_freq))
231     wcimg = wordcloud.to_array().astype(np.uint8)
232     alpha = np.full([*wcimg.shape[:2], 1], 255, dtype=np.uint8)

~/dataprep/.venv/lib/python3.8/site-packages/wordcloud/wordcloud.py in generate_from_frequencies(self, frequencies, max_font_size)
401         frequencies = sorted(frequencies.items(), key=itemgetter(1), reverse=True)
402         if len(frequencies) <= 0:
--> 403             raise ValueError("We need at least 1 word to plot a word cloud, "
404                              "got %d." % len(frequencies))
405         frequencies = frequencies[:self.max_words]

ValueError: We need at least 1 word to plot a word cloud, got 0.

# Fixed code
def stats_viz_cat(
    data: Tuple[Dict[str, str], Dict[str, str], Dict[str, str], Dict[str, str]],
    plot_width: int,
    plot_height: int,
) -> Panel:
    """
    Render statistics panel for categorical data
    """
    # pylint: disable=line-too-long
    ov_content = ""
    lens_content = ""
    qs_content = ""
    ls_content = ""
    for key, value in data[0].items():
        value = _sci_notation_superscript(value)
        if "Distinct" in key and float(value) > 50:
            ov_content += _create_table_row(key, value, True)
        elif "Unique" in key and float(value.replace("%", "")) == 100:
            ov_content += _create_table_row(key, value, True)
        elif "Missing" in key and float(value.replace("%", "")) != 0:
            ov_content += _create_table_row(key, value, True)
        else:
            ov_content += _create_table_row(key, value)
    for key, value in data[1].items():
        lens_content += _create_table_row(key, value)
    for key, value in data[2].items():
        qs_content += _create_table_row(key, value)
    for key, value in data[3].items():
        ls_content += _create_table_row(key, value)

    ov_content = f"""
    <div style="grid-area: a;">
        <h3 style="text-align: center;">Overview</h3>
        <table style="width: 100%; table-layout: auto; font-size:11px;">
            <tbody>{ov_content}</tbody>
        </table>
    </div>
    """
    qs_content = f"""
    <div style="grid-area: b;">
        <h3 style="text-align: center;">Sample</h3>
        <table style="width: 100%; table-layout: auto; font-size:11px;">
            <tbody>{qs_content}</tbody>
        </table>
    </div>
    """
    ls_content = f"""
    <div style="grid-area: c;">
        <h3 style="text-align: center;">Letter</h3>
        <table style="width: 100%; table-layout: auto; font-size:11px;">
            <tbody>{ls_content}</tbody>
        </table>
    </div>
    """
    lens_content = f"""
    <div style="grid-area: d;">
        <h3 style="text-align: center;">Length</h3>
        <table style="width: 100%; table-layout: auto; font-size:11px;">
            <tbody>{lens_content}</tbody>
        </table>
    </div>
    """

    container = f"""<div style="display: grid;grid-template-columns: 1fr 1fr;grid-template-rows: 1fr 1fr;gap: 1px 1px;
                grid-template-areas:\'a b\' \'c d\';">
                {ov_content}{qs_content}{ls_content}{lens_content}</div>"""

    div = Div(
        text=container, width=plot_width, height=plot_height, style={"width": "100%"}
    )
    return Panel(child=div, title="stats")