Skip to content

Commit 78f1942

Browse files
committed
Merge pull request matplotlib#3674 from jenshnielsen/text_warning
ENH : Silince UnicodeWarnings in tests
2 parents 5b398e9 + 5c12679 commit 78f1942

File tree

3 files changed

+52
-12
lines changed

3 files changed

+52
-12
lines changed

lib/matplotlib/mlab.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -3825,15 +3825,15 @@ def __init__(self, dataset, bw_method=None):
38253825
raise ValueError("`dataset` input should have multiple elements.")
38263826

38273827
self.dim, self.num_dp = np.array(self.dataset).shape
3828+
isString = isinstance(bw_method, six.string_types)
38283829

38293830
if bw_method is None:
38303831
pass
3831-
elif bw_method == 'scott':
3832+
elif (isString and bw_method == 'scott'):
38323833
self.covariance_factor = self.scotts_factor
3833-
elif bw_method == 'silverman':
3834+
elif (isString and bw_method == 'silverman'):
38343835
self.covariance_factor = self.silverman_factor
3835-
elif (np.isscalar(bw_method) and not
3836-
isinstance(bw_method, six.string_types)):
3836+
elif (np.isscalar(bw_method) and not isString):
38373837
self._bw_method = 'use constant'
38383838
self.covariance_factor = lambda: bw_method
38393839
elif callable(bw_method):

lib/matplotlib/tests/test_text.py

+36-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
from matplotlib.testing.decorators import image_comparison, knownfailureif, cleanup
99
import matplotlib.pyplot as plt
1010
import warnings
11-
from nose.tools import with_setup
11+
from nose import SkipTest
12+
from nose.tools import with_setup, assert_raises
1213

1314

1415
@image_comparison(baseline_images=['font_styles'])
@@ -236,3 +237,37 @@ def test_set_position():
236237

237238
for a, b in zip(init_pos.min, post_pos.min):
238239
assert a + shift_val == b
240+
241+
242+
def test_get_rotation_string():
243+
from matplotlib import text
244+
assert text.get_rotation('horizontal') == 0.
245+
assert text.get_rotation('vertical') == 90.
246+
assert text.get_rotation('15.') == 15.
247+
248+
249+
def test_get_rotation_float():
250+
from matplotlib import text
251+
for i in [15., 16.70, 77.4]:
252+
assert text.get_rotation(i) == i
253+
254+
255+
def test_get_rotation_int():
256+
from matplotlib import text
257+
for i in [67, 16, 41]:
258+
assert text.get_rotation(i) == float(i)
259+
260+
261+
def test_get_rotation_raises():
262+
from matplotlib import text
263+
import sys
264+
if sys.version_info[:2] < (2, 7):
265+
raise SkipTest("assert_raises as context manager "
266+
"not supported with Python < 2.7")
267+
with assert_raises(ValueError):
268+
text.get_rotation('hozirontal')
269+
270+
271+
def test_get_rotation_none():
272+
from matplotlib import text
273+
assert text.get_rotation(None) == 0.0

lib/matplotlib/text.py

+12-7
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,20 @@ def get_rotation(rotation):
4949
5050
*rotation* may be 'horizontal', 'vertical', or a numeric value in degrees.
5151
"""
52-
if rotation in ('horizontal', None):
53-
angle = 0.
54-
elif rotation == 'vertical':
55-
angle = 90.
56-
else:
52+
try:
5753
angle = float(rotation)
58-
return angle % 360
59-
54+
except (ValueError, TypeError):
55+
isString = isinstance(rotation, six.string_types)
56+
if ((isString and rotation == 'horizontal') or rotation is None):
57+
angle = 0.
58+
elif (isString and rotation == 'vertical'):
59+
angle = 90.
60+
else:
61+
raise ValueError("rotation is {0} expected either 'horizontal'"
62+
" 'vertical', numeric value or"
63+
"None".format(rotation))
6064

65+
return angle
6166
# these are not available for the object inspector until after the
6267
# class is build so we define an initial set here for the init
6368
# function and they will be overridden after object defn

0 commit comments

Comments
 (0)