# Buggy code
def clean_text(
    freqdist: Dict[str, int],
    non_single_word: int,
    top_words: Optional[int] = 30,
    stopword: Optional[bool] = True,
    lemmatize: Optional[bool] = False,
    stem: Optional[bool] = False,
) -> Dict[Any, Any]:
    """
    clean the frequency dictionary by stopwords, lemmatization and stemming
    """  # pylint: disable=too-many-arguments
    freq_copy = copy.deepcopy(freqdist)
    lemmatizer = WordNetLemmatizer()
    porter = PorterStemmer()
    for key in freq_copy.keys():
        if stopword and non_single_word >= top_words:  # type: ignore
            if key in english_stopwords.english_stopwords or len(key) <= 2:
                del freqdist[key]
        if lemmatize:
            if lemmatizer.lemmatize(key) != key:
                freqdist[lemmatizer.lemmatize(key)] = freqdist[key]
                del freqdist[key]
        if stem:
            if porter.stem(key) != key:
                freqdist[porter.stem(key)] = freqdist[key]
                del freqdist[key]
    return freqdist


# 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 clean_text(
    freqdist: Dict[str, int],
    non_single_word: int,
    top_words: Optional[int] = 30,
    stopword: Optional[bool] = True,
    lemmatize: Optional[bool] = False,
    stem: Optional[bool] = False,
) -> Dict[Any, Any]:
    """
    clean the frequency dictionary by stopwords, lemmatization and stemming
    """  # pylint: disable=too-many-arguments
    freq_copy = copy.deepcopy(freqdist)
    lemmatizer = WordNetLemmatizer()
    porter = PorterStemmer()
    for key in freq_copy.keys():
        if stopword and non_single_word > top_words:  # type: ignore
            if key in english_stopwords.english_stopwords or len(key) <= 2:
                del freqdist[key]
        if lemmatize:
            if lemmatizer.lemmatize(key) != key:
                freqdist[lemmatizer.lemmatize(key)] = freqdist[key]
                del freqdist[key]
        if stem:
            if porter.stem(key) != key:
                freqdist[porter.stem(key)] = freqdist[key]
                del freqdist[key]
    return freqdist