@@ -1978,19 +1978,19 @@ def make_iterable(x):
1978
1978
if len (edgecolor ) < nbars :
1979
1979
edgecolor *= nbars
1980
1980
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 )
1994
1994
1995
1995
patches = []
1996
1996
@@ -2428,8 +2428,10 @@ def pie(self, x, explode=None, labels=None, colors=None,
2428
2428
labels = ['' ] * len (x )
2429
2429
if explode is None :
2430
2430
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'" )
2433
2435
if colors is None :
2434
2436
colors = ('b' , 'g' , 'r' , 'c' , 'm' , 'y' , 'k' , 'w' )
2435
2437
@@ -3686,8 +3688,9 @@ def scatter(self, x, y, s=20, c=None, marker='o', cmap=None, norm=None,
3686
3688
collection .update (kwargs )
3687
3689
3688
3690
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 )
3691
3694
collection .set_array (np .asarray (c ))
3692
3695
collection .set_cmap (cmap )
3693
3696
collection .s
8000
et_norm (norm )
@@ -4057,8 +4060,9 @@ def hexbin(self, x, y, C=None, gridsize=100, bins=None,
4057
4060
bins = np .sort (bins )
4058
4061
accum = bins .searchsorted (accum )
4059
4062
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 )
4062
4066
collection .set_array (accum )
4063
4067
collection .set_cmap (cmap )
4064
4068
collection .set_norm (norm )
@@ -4673,8 +4677,9 @@ def imshow(self, X, cmap=None, norm=None, aspect=None,
4673
4677
if not self ._hold :
4674
4678
self .cla ()
4675
4679
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 )
4678
4683
if aspect is None :
4679
4684
aspect = rcParams ['image.aspect' ]
4680
4685
self .set_aspect (aspect )
@@ -5000,8 +5005,9 @@ def pcolor(self, *args, **kwargs):
5000
5005
5001
5006
collection .set_alpha (alpha )
5002
5007
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 )
5005
5011
collection .set_cmap (cmap )
5006
5012
collection .set_norm (norm )
5007
5013
collection .set_clim (vmin , vmax )
@@ -5149,8 +5155,9 @@ def pcolormesh(self, *args, **kwargs):
5149
5155
antialiased = antialiased , shading = shading , ** kwargs )
5150
5156
collection .set_alpha (alpha )
5151
5157
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 )
5154
5161
collection .set_cmap (cmap )
5155
5162
collection .set_norm (norm )
5156
5163
collection .set_clim (vmin , vmax )
@@ -5274,8 +5281,9 @@ def pcolorfast(self, *args, **kwargs):
5274
5281
cmap = kwargs .pop ('cmap' , None )
5275
5282
vmin = kwargs .pop ('vmin' , None )
5276
5283
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 )
5279
5287
5280
5288
C = args [- 1 ]
5281
3B4B
5289
nr , nc = C .shape
0 commit comments