@@ -1984,19 +1984,19 @@ def make_iterable(x):
19841984 if len (edgecolor ) < nbars :
19851985 edgecolor *= nbars
19861986
1987- # FIXME: convert the following to proper input validation
1988- # raising ValueError; don't use assert for this.
1989- assert len ( left ) == nbars , ("incompatible sizes: argument 'left' must "
1990- "be length %d or scalar" % nbars )
1991- assert len (height ) == nbars , ( "incompatible sizes: argument 'height' "
1992- "must be length %d or scalar" %
1993- nbars )
1994- assert len (width ) == nbars , ( "incompatible sizes: argument 'width' "
1995- "must be length %d or scalar" %
1996- nbars )
1997- assert len (bottom ) == nbars , ( "incompatible sizes: argument 'bottom' "
1998- "must be length %d or scalar" %
1999- nbars )
1987+ # input validation
1988+ if len ( left ) != nbars :
1989+ raise ValueError ("incompatible sizes: argument 'left' must "
1990+ "be length %d or scalar" % nbars )
1991+ if len (height ) != nbars :
1992+ raise ValueError ( "incompatible sizes: argument 'height' "
1993+ "must be length %d or scalar" % nbars )
1994+ if len (width ) != nbars :
1995+ raise ValueError ( "incompatible sizes: argument 'width' "
1996+ "must be length %d or scalar" % nbars )
1997+ if len (bottom ) != nbars :
1998+ raise ValueError ( "incompatible sizes: argument 'bottom' "
1999+ "must be length %d or scalar" % nbars )
20002000
20012001 patches = []
20022002
@@ -2434,8 +2434,10 @@ def pie(self, x, explode=None, labels=None, colors=None,
24342434 labels = ['' ] * len (x )
24352435 if explode is None :
24362436 explode = [0 ] * len (x )
2437- assert (len (x ) == len (labels ))
2438- assert (len (x ) == len (explode ))
2437+ if len (x ) != len (labels ):
2438+ raise ValueError ("'label' must be of length 'x'" )
2439+ if len (x ) != len (explode ):
2440+ raise ValueError ("'explode' must be of length 'x'" )
24392441 if colors is None :
24402442 colors = ('b' , 'g' , 'r' , 'c' , 'm' , 'y' , 'k' , 'w' )
24412443
@@ -3692,8 +3694,9 @@ def scatter(self, x, y, s=20, c=None, marker='o', cmap=None, norm=None,
36923694 collection .update (kwargs )
36933695
36943696 if colors is None :
3695- if norm is not None :
3696- assert (isinstance (norm , mcolors .Normalize ))
3697+ if norm is not None and not isinstance (norm , mcolors .Normalize ):
3698+ msg = "'norm' must be an instance of 'mcolors.Normalize'"
3699+ raise ValueError (msg )
36973700 collection .set_array (np .asarray (c ))
36983701 collection .set_cmap (cmap )
36993702 collection .set_norm (norm )
@@ -4063,8 +4066,9 @@ def hexbin(self, x, y, C=None, gridsize=100, bins=None,
40634066 bins = np .sort (bins )
40644067 accum = bins .searchsorted (accum )
40654068
4066- if norm is not None :
4067- assert (isinstance (norm , mcolors .Normalize ))
4069+ if norm is not None and not isinstance (norm , mcolors .Normalize ):
4070+ msg = "'norm' must be an instance of 'mcolors.Normalize'"
4071+ raise ValueError (msg )
40684072 collection .set_array (accum )
40694073 collection .set_cmap (cmap )
40704074 collection .set_norm (norm )
@@ -4679,8 +4683,9 @@ def imshow(self, X, cmap=None, norm=None, aspect=None,
46794683 if not self ._hold :
46804684 self .cla ()
46814685
4682- if norm is not None :
4683- assert (isinstance (norm , mcolors .Normalize ))
4686+ if norm is not None and not isinstance (norm , mcolors .Normalize ):
4687+ msg = "'norm' must be an instance of 'mcolors.Normalize'"
4688+ raise ValueError (msg )
46844689 if aspect is None :
46854690 aspect = rcParams ['image.aspect' ]
46864691 self .set_aspect (aspect )
@@ -5006,8 +5011,9 @@ def pcolor(self, *args, **kwargs):
50065011
50075012 collection .set_alpha (alpha )
50085013 collection .set_array (C )
5009- if norm is not None :
5010- assert (isinstance (norm , mcolors .Normalize ))
5014+ if norm is not None and not isinstance (norm , mcolors .Normalize ):
5015+ msg = "'norm' must be an instance of 'mcolors.Normalize'"
5016+ raise ValueError (msg )
50115017 collection .set_cmap (cmap )
50125018 collection .set_norm (norm )
50135019 collection .set_clim (vmin , vmax )
@@ -5155,8 +5161,9 @@ def pcolormesh(self, *args, **kwargs):
51555161 antialiased = antialiased , shading = shading , ** kwargs )
51565162 collection .set_alpha (alpha )
51575163 collection .set_array (C )
5158- if norm is not None :
5159- assert (isinstance (norm , mcolors .Normalize ))
5164+ if norm is not None and not isinstance (norm , mcolors .Normalize ):
5165+ msg = "'norm' must be an instance of 'mcolors.Normalize'"
5166+ raise ValueError (msg )
51605167 collection .set_cmap (cmap )
51615168 collection .set_norm (norm )
51625169 collection .set_clim (vmin , vmax )
@@ -5280,8 +5287,9 @@ def pcolorfast(self, *args, **kwargs):
52805287 cmap = kwargs .pop ('cmap' , None )
52815288 vmin = kwargs .pop ('vmin' , None )
52825289 vmax = kwargs .pop ('vmax' , None )
5283- if norm is not None :
5284- assert (isinstance (norm , mcolors .Normalize ))
5290+ if norm is not None and not isinstance (norm , mcolors .Normalize ):
5291+ msg = "'norm' must be an instance of 'mcolors.Normalize'"
5292+ raise ValueError (msg )
52855293
52865294 C = args [- 1 ]
52875295 nr , nc = C .shape
0 commit comments