Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix matplotlib deprecation warning and adds some minor improvements #721

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,17 @@
["wordcloud/query_integral_image.c"])],
entry_points={'console_scripts': ['wordcloud_cli=wordcloud.__main__:main']},
packages=['wordcloud'],
package_data={'wordcloud': ['stopwords', 'DroidSansMono.ttf']}
package_data={'wordcloud': ['stopwords', 'DroidSansMono.ttf']},
classifiers=[
"Development Status :: 5 - Production/Stable",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: Implementation :: CPython",
]
)
11 changes: 6 additions & 5 deletions wordcloud/wordcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class colormap_color_func(object):
"""
def __init__(self, colormap):
import matplotlib.pyplot as plt
self.colormap = plt.cm.get_cmap(colormap)
self.colormap = plt.colormaps.get_cmap(colormap)

def __call__(self, word, font_size, position, orientation,
random_state=None, **kwargs):
Expand Down Expand Up @@ -576,13 +576,14 @@ def process_text(self, text):

flags = (re.UNICODE if sys.version < '3' and type(text) is unicode # noqa: F821
else 0)
pattern = r"\w[\w']*" if self.min_word_length <= 1 else r"\w[\w']+"
regexp = self.regexp if self.regexp is not None else pattern
if self.regexp is not None:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!
This call to compile actually doesn't change anything, as the object is only used once, right?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amueller,

Really sorry for the long delay. Yes there's no change on the workflow. The ideia is to simplify.

All the tests have passed locally, do you think it's useful to include any more?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries, I'm only very sporadically on this project these days. How does this change about the re simplify, the code gets longer, right?

regexp = re.compile(self.regexp, flags)
else:
regexp = re.compile(r"\w[\w']*" if self.min_word_length <= 1 else r"\w[\w']+", flags)

words = re.findall(regexp, text, flags)
# remove 's
words = [word[:-2] if word.lower().endswith("'s") else word
for word in words]
for word in regexp.findall(text)]
# remove numbers
if not self.include_numbers:
words = [word for word in words if not word.isdigit()]
Expand Down