Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d3254ec

Browse files
committed
Raise missing ValueError in transform_angles
- Includes a small PEP8 change - Added tests to cover the `Transform.transform_angles` method
1 parent f3bf9a8 commit d3254ec

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lib/matplotlib/tests/test_transforms.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from nose.tools import assert_equal, assert_raises
1010
import numpy.testing as np_test
1111
from numpy.testing import assert_almost_equal, assert_array_equal
12+
from numpy.testing import assert_array_almost_equal
1213
from matplotlib.transforms import Affine2D, BlendedGenericTransform, Bbox
1314
from matplotlib.path import Path
1415
from matplotlib.scale import LogScale
@@ -535,6 +536,21 @@ def test_nan_overlap():
535536
assert not a.overlaps(b)
536537

537538

539+
def test_transform_angles():
540+
t = mtrans.Affine2D()
541+
angles = np.array([20, 45, 60])
542+
points = np.array([[0, 0], [1, 1], [2, 2]])
543+
544+
new_angles = t.transform_angles(angles, points)
545+
assert_array_almost_equal(angles, new_angles)
546+
547+
with assert_raises(ValueError) as cm:
548+
t.transform_angles(angles, points[0:2, 0:1])
549+
550+
with assert_raises(ValueError) as cm:
551+
t.transform_angles(angles, points[0:2, :])
552+
553+
538554
if __name__ == '__main__':
539555
import nose
540556
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

lib/matplotlib/transforms.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1468,9 +1468,10 @@ def transform_angles(self, angles, pts, radians=False, pushoff=1e-5):
14681468
if pts.shape[1] != 2:
14691469
raise ValueError("'pts' must be array with 2 columns for x,y")
14701470

1471-
if angles.ndim!=1 or angles.shape[0] != pts.shape[0]:
1471+
if angles.ndim != 1 or angles.shape[0] != pts.shape[0]:
14721472
msg = "'angles' must be a column vector and have same number of"
14731473
msg += " rows as 'pts'"
1474+
raise ValueError(msg)
14741475

14751476
# Convert to radians if desired
14761477
if not radians:

0 commit comments

Comments
 (0)