@@ -593,7 +593,8 @@ def shrunk_to_aspect(self, box_aspect, container=None, fig_aspect=1.0):
593
593
*fig_aspect*, so that *box_aspect* can also be given as a
594
594
ratio of the absolute dimensions, not the relative dimensions.
595
595
"""
596
- assert box_aspect > 0 and fig_aspect > 0
596
+ if box_aspect <= 0 or fig_aspect <= 0 :
597
+ raise ValueError ("'box_aspect' and 'fig_aspect' must be positive" )
597
598
if container is None :
598
599
container = self
599
600
w , h = container .size
@@ -719,7 +720,8 @@ def union(bboxes):
719
720
"""
720
721
Return a :class:`Bbox` that contains all of the given bboxes.
721
722
"""
722
- assert (len (bboxes ))
723
+ if not len (bboxes ):
724
+ raise ValueError ("'bboxes' cannot be empty" )
723
725
724
726
if len (bboxes ) == 1 :
725
727
return bboxes [0 ]
@@ -1062,10 +1064,15 @@ def __init__(self, bbox, transform, **kwargs):
1062
1064
1063
1065
*transform*: a 2D :class:`Transform`
1064
1066
"""
1065
- assert bbox .is_bbox
1066
- assert isinstance (transform , Transform )
1067
- assert transform .input_dims == 2
1068
- assert transform .output_dims == 2
1067
+ if not bbox .is_bbox :
1068
+ raise ValueError ("'bbox' is not a bbox" )
1069
+ if not isinstance (transform , Transform ):
1070
+ msg = "'transform' must be an instance of"
1071
+ msg += " 'matplotlib.transform.Transform'"
1072
+ raise ValueError (msg )
1073
+ if transform .input_dims != 2 or transform .output_dims != 2 :
1074
+ msg = "The input and output dimensions of 'transform' must be 2"
1075
+ raise ValueError (msg )
1069
1076
1070
1077
BboxBase .__init__ (self , ** kwargs )
1071
1078
self ._bbox = bbox
@@ -1384,7 +1391,9 @@ def transform_point(self, point):
1384
1391
The transformed point is returned as a sequence of length
1385
1392
:attr:`output_dims`.
1386
1393
"""
1387
- assert len (point ) == self .input_dims
1394
+ if len (point ) != self .input_dims :
1395
+ msg = "The length of 'point' must be 'self.input_dims'"
1396
+ raise ValueError (msg )
1388
1397
return self .transform (np .asarray ([point ]))[0 ]
1389
1398
1390
1399
def transform_path (self , path ):
@@ -1454,12 +1463,12 @@ def transform_angles(self, angles, pts, radians=False, pushoff=1e-5):
1454
1463
if self .input_dims != 2 or self .output_dims != 2 :
1455
1464
raise NotImplementedError ('Only defined in 2D' )
1456
1465
1457
- # pts must be array with 2 columns for x,y
1458
- assert pts . shape [ 1 ] == 2
1466
+ if pts . shape [ 1 ] != 2 :
1467
+ raise ValueError ( "' pts' must be array with 2 columns for x,y" )
1459
1468
1460
- # angles must be a column vector and have same number of
1461
- # rows as pts
1462
- assert np . prod ( angles . shape ) == angles . shape [ 0 ] == pts . shape [ 0 ]
1469
+ if angles . ndim != 1 or angles . shape [ 0 ] != pts . shape [ 0 ]:
1470
+ msg = "'angles' must be a column vector and have same number of"
1471
+ msg += " rows as ' pts'"
1463
1472
1464
1473
# Convert to radians if desired
1465
1474
if not radians :
@@ -1516,7 +1525,10 @@ def __init__(self, child):
1516
1525
*child*: A class:`Transform` instance. This child may later
1517
1526
be replaced with :meth:`set`.
1518
1527
"""
1519
- assert isinstance (child , Transform )
1528
+ if not isinstance (child , Transform ):
1529
+ msg = "'child' must be an instance of"
1530
+ msg += " 'matplotlib.transform.Transform'"
1531
+ raise ValueError (msg )
1520
1532
Transform .__init__ (self )
1521
1533
self .input_dims = child .input_dims
1522
1534
self .output_dims = child .output_dims
@@ -1571,8 +1583,11 @@ def set(self, child):
1571
1583
The new child must have the same number of input and output
1572
1584
dimensions as the current child.
1573
1585
"""
1574
- assert child .input_dims == self .input_dims
1575
- assert child .output_dims == self .output_dims
1586
+ if child .input_dims != self .input_dims or \
1587
+ child .output_dims != self .output_dims :
1588
+ msg = "The new child must have the same number of input and output"
1589
+ msg += " dimensions as the current child."
1590
+ raise ValueError (msg )
1576
1591
1577
1592
self ._set (child )
1578
1593
@@ -1822,7 +1837,10 @@ def set(self, other):
1822
1837
Set this transformation from the frozen copy of another
1823
1838
:class:`Affine2DBase` object.
1824
1839
"""
1825
- assert isinstance (other , Affine2DBase )
1840
+ if not isinstance (other , Affine2DBase ):
1841
+ msg = "'other' must be an instance of"
1842
+ msg += " 'matplotlib.transform.Affine2DBase'"
1843
+ raise ValueError (msg )
1826
1844
self ._mtx = other .get_matrix ()
1827
1845
self .invalidate ()
1828
1846
@@ -2152,10 +2170,13 @@ def __init__(self, x_transform, y_transform, **kwargs):
2152
2170
can determine automatically which kind of blended transform to
2153
2171
create.
2154
2172
"""
2155
- assert x_transform .is_affine
2156
- assert y_transform .is_affine
2157
- assert x_transform .is_separable
2158
- assert y_transform .is_separable
2173
+ is_affine = x_transform .is_affine and y_transform .is_affine
2174
+ is_separable = x_transform .is_separable and y_transform .is_separable
2175
+ is_correct = is_correct and is_separable
2176
+ if not is_correct :
2177
+ msg = "Both *x_transform* and *y_transform* must be 2D affine"
2178
+ msg += " transforms."
2179
+ raise ValueError (msg )
2159
2180
2160
2181
Transform .__init__ (self , ** kwargs )
2161
2182
self ._x = x_transform
@@ -2232,7 +2253,10 @@ def __init__(self, a, b, **kwargs):
2232
2253
which can automatically choose the best kind of composite
2233
2254
transform instance to create.
2234
2255
"""
2235
- assert a .output_dims == b .input_dims
2256
+ if a .output_dims != b .input_dims :
2257
+ msg = "The output dimension of 'a' must be equal to the input"
2258
+ msg += " dimensions of 'b'"
2259
+ raise ValueError (msg )
2236
2260
self .input_dims = a .input_dims
2237
2261
self .output_dims = b .output_dims
2238
2262
@@ -2357,11 +2381,14 @@ def __init__(self, a, b, **kwargs):
2357
2381
which can automatically choose the best kind of composite
2358
2382
transform instance to create.
2359
2383
"""
2360
- assert a .output_dims == b .input_dims
2384
+ if not a .is_affine or not b .is_affine :
2385
+ raise ValueError ("'a' and 'b' must be affine transforms" )
2386
+ if a .output_dims != b .input_dims :
2387
+ msg = "The output dimension of 'a' must be equal to the input"
2388
+ msg += " dimensions of 'b'"
2389
+ raise ValueError (msg )
2361
2390
self .input_dims = a .input_dims
2362
2391
self .output_dims = b .output_dims
2363
- assert a .is_affine
2364
- assert b .is_affine
2365
2392
2366
2393
Affine2DBase .__init__ (self , ** kwargs )
2367
2394
self ._a = a
@@ -2436,8 +2463,8 @@ def __init__(self, boxin, boxout, **kwargs):
2436
2463
Create a new :class:`BboxTransform` that linearly transforms
2437
2464
points from *boxin* to *boxout*.
2438
2465
"""
2439
- assert boxin .is_bbox
2440
- assert boxout . is_bbox
2466
+ if not boxin .is_bbox or not boxout . is_bbox :
2467
+ msg = "'boxin' and ' boxout' must be bbox"
2441
2468
2442
2469
Affine2DBase .__init__ (self , ** kwargs )
2443
2470
self ._boxin = boxin
@@ -2480,7 +2507,8 @@ def __init__(self, boxout, **kwargs):
2480
2507
Create a new :class:`BboxTransformTo` that linearly transforms
2481
2508
points from the unit bounding box to *boxout*.
2482
2509
"""
2483
- assert boxout .is_bbox
2510
+ if not boxout .is_bbox :
2511
+ raise ValueError ("'boxout' must be bbox" )
2484
2512
2485
2513
Affine2DBase .__init__ (self , ** kwargs )
2486
2514
self ._boxout = boxout
@@ -2538,7 +2566,8 @@ class BboxTransformFrom(Affine2DBase):
2538
2566
is_separable = True
2539
2567
2540
2568
def __init__ (self , boxin , ** kwargs ):
2541
- assert boxin .is_bbox
2569
+ if not boxin .is_bbox :
2570
+ raise ValueError ("'boxin' must be bbox" )
2542
2571
2543
2572
Affine2DBase .__init__ (self , ** kwargs )
2544
2573
self ._boxin = boxin
@@ -2613,7 +2642,10 @@ def __init__(self, path, transform):
2613
2642
Create a new :class:`TransformedPath` from the given
2614
2643
:class:`~matplotlib.path.Path` and :class:`Transform`.
2615
2644
"""
2616
- assert isinstance (transform , Transform )
2645
+ if not isinstance (transform , Transform ):
2646
+ msg = "'transform' must be an instance of"
2647
+ msg += " 'matplotlib.transform.Transform'"
2648
+ raise ValueError (msg )
2617
2649
TransformNode .__init__ (self )
2618
2650
2619
2651
self ._path = path
0 commit comments