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

Skip to content

Commit e1a52a9

Browse files
committed
Merge pull request #4458 from has2k1/fix-transform-angles-unraised-error
Raise missing ValueError in transform_angles
2 parents 128e99a + 06d0892 commit e1a52a9

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/matplotlib/tests/test_transforms.py

Lines changed: 17 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,22 @@ def test_nan_overlap():
535536
assert not a.overlaps(b)
536537

537538

539+
def test_transform_angles():
540+
t = mtrans.Affine2D() # Identity transform
541+
angles = np.array([20, 45, 60])
542+
points = np.array([[0, 0], [1, 1], [2, 2]])
543+
544+
# Identity transform does not change angles
545+
new_angles = t.transform_angles(angles, points)
546+
assert_array_almost_equal(angles, new_angles)
547+
548+
# points missing a 2nd dimension
549+
assert_raises(ValueError, t.transform_angles, angles, points[0:2, 0:1])
550+
551+
# Number of angles != Number of points
552+
assert_raises(ValueError, t.transform_angles, angles, points[0:2, :])
553+
554+
538555
if __name__ == '__main__':
539556
import nose
540557
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)