Skip to content

Commit a56ea63

Browse files
committed
API : Only allow addition of equal length cycles
Now that we have both multiplication and slicing, it is easy to get correct length cyclers to add together
1 parent 126d7df commit a56ea63

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

lib/matplotlib/cycler.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ def __iter__(self):
110110
return self._compose()
111111

112112
def __add__(self, other):
113+
if len(self) != len(other):
114+
raise ValueError("Can only add equal length cycles, "
115+
"not {0} and {1}".format(len(self), len(other)))
113116
return Cycler(self, other, zip)
114117

115118
def __mul__(self, other):

lib/matplotlib/tests/test_cycler.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,8 @@ def test_compose():
3939
yield _cycler_helper, c2+c1, 3, ['c', 'lw'], [list('rgb'), range(3)]
4040
yield _cycles_equal, c2+c1, c1+c2
4141
# miss-matched add lengths
42-
yield _cycler_helper, c1+c3, 3, ['c', 'lw'], [list('rgb'), range(3)]
43-
yield _cycler_helper, c3+c1, 3, ['c', 'lw'], [list('rgb'), range(3)]
44-
yield _cycles_equal, c3+c1, c1+c3
42+
assert_raises(ValueError, add, c1, c3)
43+
assert_raises(ValueError, add, c3, c1)
4544

4645
# multiplication
4746
target = zip(*product(list('rgb'), range(3)))

0 commit comments

Comments
 (0)