# Buggy code
def pie_viz(
    df: pd.DataFrame,
    col: str,
    miss_pct: float,
    plot_width: int,
    plot_height: int,
) -> Panel:
    """
    Render a pie chart
    """
    title = f"{col} ({miss_pct}% missing)" if miss_pct > 0 else f"{col}"
    tooltips = [(f"{col}", "@col"), ("Count", "@cnt"), ("Percent", "@pct{0.2f}%")]
    df["angle"] = df["cnt"] / df["cnt"].sum() * 2 * pi
    fig = Figure(
        title=title,
        plot_width=plot_width,
        plot_height=plot_height,
        tools="hover",
        toolbar_location=None,
        tooltips=tooltips,
    )
    color_list = PALETTE * (len(df) // len(PALETTE) + 1)
    df["colour"] = color_list[0 : len(df)]
    if df.iloc[-1]["cnt"] == 0:  # no "Others" group
        df = df[:-1]
    df["col"] = df["col"].map(lambda x: x[0:13] + "..." if len(x) > 13 else x)
    pie = fig.wedge(
        x=0,
        y=1,
        radius=0.9,
        start_angle=cumsum("angle", include_zero=True),
        end_angle=cumsum("angle"),
        line_color="white",
        fill_color="colour",
        source=df,
    )
    legend = Legend(items=[LegendItem(label=dict(field="col"), renderers=[pie])])
    legend.label_text_font_size = "8pt"
    fig.add_layout(legend, "right")
    tweak_figure(fig, "pie")
    fig.axis.major_label_text_font_size = "0pt"
    fig.axis.major_tick_line_color = None
    return Panel(child=row(fig), title="pie chart")


# 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 pie_viz(
    df: pd.DataFrame,
    col: str,
    miss_pct: float,
    plot_width: int,
    plot_height: int,
) -> Panel:
    """
    Render a pie chart
    """
    title = f"{col} ({miss_pct}% missing)" if miss_pct > 0 else f"{col}"
    tooltips = [(f"{col}", "@col"), ("Count", "@cnt"), ("Percent", "@pct{0.2f}%")]
    df["angle"] = df["cnt"] / df["cnt"].sum() * 2 * pi
    fig = Figure(
        title=title,
        plot_width=plot_width,
        plot_height=plot_height,
        tools="hover",
        toolbar_location=None,
        tooltips=tooltips,
    )
    color_list = PALETTE * (len(df) // len(PALETTE) + 1)
    df["colour"] = color_list[0 : len(df)]
    df["col"] = df["col"].map(lambda x: x[0:13] + "..." if len(x) > 13 else x)

    if df.iloc[-1]["cnt"] == 0:  # no "Others" group
        df = df.iloc[:-1]

    pie = fig.wedge(
        x=0,
        y=1,
        radius=0.9,
        start_angle=cumsum("angle", include_zero=True),
        end_angle=cumsum("angle"),
        line_color="white",
        fill_color="colour",
        source=df,
    )
    legend = Legend(items=[LegendItem(label=dict(field="col"), renderers=[pie])])
    legend.label_text_font_size = "8pt"
    fig.add_layout(legend, "right")
    tweak_figure(fig, "pie")
    fig.axis.major_label_text_font_size = "0pt"
    fig.axis.major_tick_line_color = None
    return Panel(child=row(fig), title="pie chart")