Skip to content

Commit

Permalink
Add safeguard to accept only dictionary for frequency functions
Browse files Browse the repository at this point in the history
A condition to check for dictionary in the `generate_from_frequencies` function.
  • Loading branch information
Ahmed-Ashraf-Marzouk authored Jan 13, 2025
1 parent ec24191 commit 73aa3bb
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions wordcloud/wordcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,11 @@ def generate_from_frequencies(self, frequencies, max_font_size=None): # noqa: C
self
"""

# make sure frequencies are of type dict
if not insanceof(frequencies, dict):
raise TypeError(f"Expected argument of type 'dict', but got {type(frequencies).__name__}")

# make sure frequencies are sorted and normalized
frequencies = sorted(frequencies.items(), key=itemgetter(1), reverse=True)
if len(frequencies) <= 0:
Expand Down

0 comments on commit 73aa3bb

Please sign in to comment.