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

Teriterance fixes test #705

Closed
wants to merge 4 commits into from
Closed
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
10 changes: 5 additions & 5 deletions test/test_wordcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,14 @@ def test_mask():
# check that using an empty mask is equivalent to not using a mask
wc = WordCloud(random_state=42)
wc.generate(THIS)
mask = np.zeros(np.array(wc).shape[:2], dtype=np.int)
mask = np.zeros(np.array(wc).shape[:2], dtype=np.int32)
wc_mask = WordCloud(mask=mask, random_state=42)
wc_mask.generate(THIS)
assert_array_equal(wc, wc_mask)

# use actual nonzero mask
mask = np.zeros((234, 456), dtype=np.int)
mask[100:150, 300:400] = 255
mask = np.zeros((234, 456), dtype=np.int32)
mask[0:150, 0:400] = 255

wc = WordCloud(mask=mask)
wc.generate(THIS)
Expand All @@ -259,7 +259,7 @@ def test_mask():
def test_mask_contour():
# test mask contour is created, learn more at:
# https://github.com/amueller/word_cloud/pull/348#issuecomment-370883873
mask = np.zeros((234, 456), dtype=np.int)
mask = np.zeros((234, 456), dtype=np.int32)
mask[100:150, 300:400] = 255

sm = WordCloud(mask=mask, contour_width=1, contour_color='blue')
Expand Down Expand Up @@ -491,7 +491,7 @@ def test_max_font_size_as_mask_height():
size = (default_size[0] * 2, default_size[1] * 2)

# using mask, all drawable
mask = np.zeros(size, dtype=np.int)
mask = np.zeros(size, dtype=np.int32)
mask[:, :] = 0
wc = WordCloud(mask=mask, random_state=42)
wc.generate(x)
Expand Down
12 changes: 6 additions & 6 deletions wordcloud/wordcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ def generate_from_frequencies(self, frequencies, max_font_size=None): # noqa: C
if random_state.random() < self.prefer_horizontal:
orientation = None
else:
orientation = Image.ROTATE_90
orientation = Image.Transpose.ROTATE_90
tried_other_orientation = False
while True:
# try to find a position
Expand All @@ -505,7 +505,7 @@ def generate_from_frequencies(self, frequencies, max_font_size=None): # noqa: C
transposed_font = ImageFont.TransposedFont(
font, orientation=orientation)
# get size of resulting text
box_size = draw.textsize(word, font=transposed_font)
box_size = draw.textbbox(text=word, font=transposed_font)
# find possible places using integral image:
result = occupancy.sample_position(box_size[1] + self.margin,
box_size[0] + self.margin,
Expand All @@ -516,8 +516,8 @@ def generate_from_frequencies(self, frequencies, max_font_size=None): # noqa: C
# if we didn't find a place, make font smaller
# but first try to rotate!
if not tried_other_orientation and self.prefer_horizontal < 1:
orientation = (Image.ROTATE_90 if orientation is None else
Image.ROTATE_90)
orientation = (Image.Transpose.ROTATE_90 if orientation is None else
Image.Transpose.ROTATE_90)
tried_other_orientation = True
else:
font_size -= self.font_step
Expand Down Expand Up @@ -961,7 +961,7 @@ def to_svg(self, embed_font=False, optimize_embedded_font=True, embed_image=Fals

# Compute text attributes
attributes = {}
if orientation == Image.ROTATE_90:
if orientation == Image.Transpose.ROTATE_90:
x += max_y
y += max_x - min_x
transform = 'translate({},{}) rotate(-90)'.format(x, y)
Expand Down Expand Up @@ -1036,4 +1036,4 @@ def _draw_contour(self, img):
color = Image.new(img.mode, img.size, self.contour_color)
ret += np.array(color) * contour

return Image.fromarray(ret)
return Image.fromarray(ret)