Skip to content

Commit

Permalink
Raise missing ValueError in transform_angles
Browse files Browse the repository at this point in the history
- Includes a small PEP8 change
- Added tests to cover the `Transform.transform_angles` method
  • Loading branch information
has2k1 committed May 23, 2015
1 parent f3bf9a8 commit 06d0892
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
17 changes: 17 additions & 0 deletions lib/matplotlib/tests/test_transforms.py
Expand Up @@ -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
Expand Down Expand Up @@ -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)
3 changes: 2 additions & 1 deletion lib/matplotlib/transforms.py
Expand Up @@ -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:
Expand Down

0 comments on commit 06d0892

Please sign in to comment.