8000 most asserts modified to ValueError · matplotlib/matplotlib@34c6a5f · GitHub
[go: up one dir, main page]

Skip to content

Commit 34c6a5f

Browse files
committed
most asserts modified to ValueError
1 parent 187f584 commit 34c6a5f

File tree

1 file changed

+35
-27
lines changed

1 file changed

+35
-27
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1978,19 +1978,19 @@ def make_iterable(x):
19781978
if len(edgecolor) < nbars:
19791979
edgecolor *= nbars
19801980

1981-
# FIXME: convert the following to proper input validation
1982-
# raising ValueError; don't use assert for this.
1983-
assert len(left) == nbars, ("incompatible sizes: argument 'left' must "
1984-
"be length %d or scalar" % nbars)
1985-
assert len(height) == nbars, ("incompatible sizes: argument 'height' "
1986-
"must be length %d or scalar" %
1987-
nbars)
1988-
assert len(width) == nbars, ("incompatible sizes: argument 'width' "
1989-
"must be length %d or scalar" %
1990-
nbars)
1991-
assert len(bottom) == nbars, ("incompatible sizes: argument 'bottom' "
1992-
"must be length %d or scalar" %
1993-
nbars)
1981+
# input validation
1982+
if len(left) != nbars:
1983+
raise ValueError("incompatible sizes: argument 'left' must "
1984+
"be length %d or scalar" % nbars)
1985+
if len(height) != nbars:
1986+
raise ValueError("incompatible sizes: argument 'height' "
1987+
"must be length %d or scalar" % nbars)
1988+
if len(width) != nbars:
1989+
raise ValueError("incompatible sizes: argument 'width' "
1990+
"must be length %d or scalar" % nbars)
1991+
if len(bottom) == nbars:
1992+
raise ValueError("incompatible sizes: argument 'bottom' "
1993+
"must be length %d or scalar" % nbars)
19941994

19951995
patches = []
19961996

@@ -2428,8 +2428,10 @@ def pie(self, x, explode=None, labels=None, colors=None,
24282428
labels = [''] * len(x)
24292429
if explode is None:
24302430
explode = [0] * len(x)
2431-
assert(len(x) == len(labels))
2432-
assert(len(x) == len(explode))
2431+
if len(x) != len(labels):
2432+
raise ValueError("'label' must be of length 'x'")
2433+
if len(x) != len(explode):
2434+
raise ValueError("'explode' must be of length 'x'")
24332435
if colors is None:
24342436
colors = ('b', 'g', 'r', 'c', 'm', 'y', 'k', 'w')
24352437

@@ -3686,8 +3688,9 @@ def scatter(self, x, y, s=20, c=None, marker='o', cmap=None, norm=None,
36863688
collection.update(kwargs)
36873689

36883690
if colors is None:
3689-
if norm is not None:
3690-
assert(isinstance(norm, mcolors.Normalize))
3691+
if norm is not None and not isinstance(norm, mcolors.Normalize):
3692+
msg = "'norm' must be an instance of 'mcolors.Normalize'"
3693+
raise ValueError(msg)
36913694
collection.set_array(np.asarray(c))
36923695
collection.set_cmap(cmap)
36933696
collection.s 8000 et_norm(norm)
@@ -4057,8 +4060,9 @@ def hexbin(self, x, y, C=None, gridsize=100, bins=None,
40574060
bins = np.sort(bins)
40584061
accum = bins.searchsorted(accum)
40594062

4060-
if norm is not None:
4061-
assert(isinstance(norm, mcolors.Normalize))
4063+
if norm is not None and not isinstance(norm, mcolors.Normalize):
4064+
msg = "'norm' must be an instance of 'mcolors.Normalize'"
4065+
raise ValueError(msg)
40624066
collection.set_array(accum)
40634067
collection.set_cmap(cmap)
40644068
collection.set_norm(norm)
@@ -4673,8 +4677,9 @@ def imshow(self, X, cmap=None, norm=None, aspect=None,
46734677
if not self._hold:
46744678
self.cla()
46754679

4676-
if norm is not None:
4677-
assert(isinstance(norm, mcolors.Normalize))
4680+
if norm is not None and not isinstance(norm, mcolors.Normalize):
4681+
msg = "'norm' must be an instance of 'mcolors.Normalize'"
4682+
raise ValueError(msg)
46784683
if aspect is None:
46794684
aspect = rcParams['image.aspect']
46804685
self.set_aspect(aspect)
@@ -5000,8 +5005,9 @@ def pcolor(self, *args, **kwargs):
50005005

50015006
collection.set_alpha(alpha)
50025007
collection.set_array(C)
5003-
if norm is not None:
5004-
assert(isinstance(norm, mcolors.Normalize))
5008+
if norm is not None and not isinstance(norm, mcolors.Normalize):
5009+
msg = "'norm' must be an instance of 'mcolors.Normalize'"
5010+
raise ValueError(msg)
50055011
collection.set_cmap(cmap)
50065012
collection.set_norm(norm)
50075013
collection.set_clim(vmin, vmax)
@@ -5149,8 +5155,9 @@ def pcolormesh(self, *args, **kwargs):
51495155
antialiased=antialiased, shading=shading, **kwargs)
51505156
collection.set_alpha(alpha)
51515157
collection.set_array(C)
5152-
if norm is not None:
5153-
assert(isinstance(norm, mcolors.Normalize))
5158+
if norm is not None and not isinstance(norm, mcolors.Normalize):
5159+
msg = "'norm' must be an instance of 'mcolors.Normalize'"
5160+
raise ValueError(msg)
51545161
collection.set_cmap(cmap)
51555162
collection.set_norm(norm)
51565163
collection.set_clim(vmin, vmax)
@@ -5274,8 +5281,9 @@ def pcolorfast(self, *args, **kwargs):
52745281
cmap = kwargs.pop('cmap', None)
52755282
vmin = kwargs.pop('vmin', None)
52765283
vmax = kwargs.pop('vmax', None)
5277-
if norm is not None:
5278-
assert(isinstance(norm, mcolors.Normalize))
5284+
if norm is not None and not isinstance(norm, mcolors.Normalize):
5285+
msg = "'norm' must be an instance of 'mcolors.Normalize'"
5286+
raise ValueError(msg)
52795287

52805288
C = args[-1]
5281 3B4B 5289
nr, nc = C.shape

0 commit comments

Comments
 (0)
0