From 06d0892a99ac5c5c11aebdd0e61ecb6039429f7b Mon Sep 17 00:00:00 2001 From: Hassan Kibirige Date: Sat, 23 May 2015 03:16:49 -0500 Subject: [PATCH] Raise missing ValueError in transform_angles - Includes a small PEP8 change - Added tests to cover the `Transform.transform_angles` method --- lib/matplotlib/tests/test_transforms.py | 17 +++++++++++++++++ lib/matplotlib/transforms.py | 3 ++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/tests/test_transforms.py b/lib/matplotlib/tests/test_transforms.py index 48a69404f467..c43f3a49984f 100644 --- a/lib/matplotlib/tests/test_transforms.py +++ b/lib/matplotlib/tests/test_transforms.py @@ -9,6 +9,7 @@ from nose.tools import assert_equal, assert_raises import numpy.testing as np_test from numpy.testing import assert_almost_equal, assert_array_equal +from numpy.testing import assert_array_almost_equal from matplotlib.transforms import Affine2D, BlendedGenericTransform, Bbox from matplotlib.path import Path from matplotlib.scale import LogScale @@ -535,6 +536,22 @@ def test_nan_overlap(): assert not a.overlaps(b) +def test_transform_angles(): + t = mtrans.Affine2D() # Identity transform + angles = np.array([20, 45, 60]) + points = np.array([[0, 0], [1, 1], [2, 2]]) + + # Identity transform does not change angles + new_angles = t.transform_angles(angles, points) + assert_array_almost_equal(angles, new_angles) + + # points missing a 2nd dimension + assert_raises(ValueError, t.transform_angles, angles, points[0:2, 0:1]) + + # Number of angles != Number of points + assert_raises(ValueError, t.transform_angles, angles, points[0:2, :]) + + if __name__ == '__main__': import nose nose.runmodule(argv=['-s', '--with-doctest'], exit=False) diff --git a/lib/matplotlib/transforms.py b/lib/matplotlib/transforms.py index 5c343e466ed3..f7ff31f42e5b 100644 --- a/lib/matplotlib/transforms.py +++ b/lib/matplotlib/transforms.py @@ -1468,9 +1468,10 @@ def transform_angles(self, angles, pts, radians=False, pushoff=1e-5): if pts.shape[1] != 2: raise ValueError("'pts' must be array with 2 columns for x,y") - if angles.ndim!=1 or angles.shape[0] != pts.shape[0]: + if angles.ndim != 1 or angles.shape[0] != pts.shape[0]: msg = "'angles' must be a column vector and have same number of" msg += " rows as 'pts'" + raise ValueError(msg) # Convert to radians if desired if not radians: