8000 asserts removed from t* file. test and tri directories ignored · matplotlib/matplotlib@d12fbb8 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit d12fbb8

Browse files
committed
asserts removed from t* file. test and tri directories ignored
1 parent 9e4b911 commit d12fbb8

File tree

4 files changed

+78
-40
lines changed

4 files changed

+78
-40
lines changed

lib/matplotlib/table.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ class Table(Artist):
154154
155155
Each entry in the table can be either text or patches.
156156
157-
Column widths and row heights for the table can be specifified.
157+
Column widths and row heights for the table can be specified.
158158
159159
Return value is a sequence of text, line and patch instances that make
160160
up the table
@@ -482,12 +482,17 @@ def table(ax,
482482
rows = len(cellText)
483483
cols = len(cellText[0])
484484
for row in cellText:
485-
assert len(row) == cols
485+
if len(row) != cols:
486+
msg = "Each row in 'cellText' must have {} columns"
487+
raise ValueError(msg.format(cols))
486488

487489
if cellColours is not None:
488-
assert len(cellColours) == rows
490+
if len(cellColours) != rows:
491+
raise ValueError("'cellColours' must have {} rows".format(rows))
489492
for row in cellColours:
490-
assert len(row) == cols
493+
if len(row) != cols:
494+
msg = "Each row in 'cellColours' must have {} columns"
495+
raise ValueError(msg.format(cols))
491496
else:
492497
cellColours = ['w' * cols] * rows
493498

@@ -506,7 +511,8 @@ def table(ax,
506511
rowColours = 'w' * rows
507512

508513
if rowLabels is not None:
509-
assert len(rowLabels) == rows
514+
if len(rowLabels) != rows:
515+
raise ValueError("'rowLabels' must be of length {}".format(rows))
510516

511517
# If we have column labels, need to shift
512518
# the text and colour arrays down 1 row
@@ -519,9 +525,6 @@ def table(ax,
519525
elif colColours is None:
520526
colColours = 'w' * cols
521527

522-
if rowLabels is not None:
523-
assert len(rowLabels) == rows
524-
525528
# Set up cell colours if not given
526529
if cellColours is None:
527530
cellColours = ['w' * cols] * rows

lib/matplotlib/text.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1474,7 +1474,8 @@ def __init__(self, artist, ref_coord, unit="points"):
14741474
self.set_unit(unit)
14751475

14761476
def set_unit(self, unit):
1477-
assert unit in ["points", "pixels"]
1477+
if unit not in ["points", "pixels"]:
1478+
raise ValueError("'unit' must be one of ['points', 'pixels']")
14781479
self._unit = unit
14791480

14801481
def get_unit(self):

lib/matplotlib/ticker.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,8 @@ def set_powerlimits(self, lims):
464464
greater than 1e4.
465465
See also :meth:`set_scientific`.
466466
'''
467-
assert len(lims) == 2, "argument must be a sequence of length 2"
467+
if len(lims) != 2:
468+
raise ValueError("'lims' must be a sequence of length 2")
468469
self._powerlimits = lims
469470

470471
def format_data_short(self, value):
@@ -1201,7 +1202,8 @@ def closeto(x, y):
12011202
class Base(object):
12021203
'this solution has some hacks to deal with floating point inaccuracies'
12031204
def __init__(self, base):
1204-
assert(base > 0)
1205+
if base <= 0:
1206+
raise ValueError("'base' must be positive")
12051207
self._base = base
12061208

12071209
def lt(self, x):

lib/matplotlib/transforms.py

Lines changed: 61 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,8 @@ def shrunk_to_aspect(self, box_aspect, container=None, fig_aspect=1.0):
593593
*fig_aspect*, so that *box_aspect* can also be given as a
594594
ratio of the absolute dimensions, not the relative dimensions.
595595
"""
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")
597598
if container is None:
598599
container = self
599600
w, h = container.size
@@ -719,7 +720,8 @@ def union(bboxes):
719720
"""
720721
Return a :class:`Bbox` that contains all of the given bboxes.
721722
"""
722-
assert(len(bboxes))
723+
if not len(bboxes):
724+
raise ValueError("'bboxes' cannot be empty")
723725

724726
if len(bboxes) == 1:
725727
return bboxes[0]
@@ -1062,10 +1064,15 @@ def __init__(self, bbox, transform, **kwargs):
10621064
10631065
*transform*: a 2D :class:`Transform`
10641066
"""
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)
10691076

10701077
BboxBase.__init__(self, **kwargs)
10711078
self._bbox = bbox
@@ -1384,7 +1391,9 @@ def transform_point(self, point):
13841391
The transformed point is returned as a sequence of length
13851392
:attr:`output_dims`.
13861393
"""
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)
13881397
return self.transform(np.asarray([point]))[0]
13891398

13901399
def transform_path(self, path):
@@ -1454,12 +1463,12 @@ def transform_angles(self, angles, pts, radians=False, pushoff=1e-5):
14541463
if self.input_dims != 2 or self.output_dims != 2:
14551464
raise NotImplementedError('Only defined in 2D')
14561465

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")
14591468

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'"
14631472

14641473
# Convert to radians if desired
14651474
if not radians:
@@ -1516,7 +1525,10 @@ def __init__(self, child):
15161525
*child*: A class:`Transform` instance. This child may later
15171526
be replaced with :meth:`set`.
15181527
"""
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)
15201532
Transform.__init__(self)
15211533
self.input_dims = child.input_dims
15221534
self.output_dims = child.output_dims
@@ -1571,8 +1583,11 @@ def set(self, child):
15711583
The new child must have the same number of input and output
15721584
dimensions as the current child.
15731585
"""
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)
15761591

15771592
self._set(child)
15781593

@@ -1822,7 +1837,10 @@ def set(self, other):
18221837
Set this transformation from the frozen copy of another
18231838
:class:`Affine2DBase` object.
18241839
"""
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)
18261844
self._mtx = other.get_matrix()
18271845
self.invalidate()
18281846

@@ -2152,10 +2170,13 @@ def __init__(self, x_transform, y_transform, **kwargs):
21522170
can determine automatically which kind of blended transform to
21532171
create.
21542172
"""
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)
21592180

21602181
Transform.__init__(self, **kwargs)
21612182
self._x = x_transform
@@ -2232,7 +2253,10 @@ def __init__(self, a, b, **kwargs):
22322253
which can automatically choose the best kind of composite
22332254
transform instance to create.
22342255
"""
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)
22362260
self.input_dims = a.input_dims
22372261
self.output_dims = b.output_dims
22382262

@@ -2357,11 +2381,14 @@ def __init__(self, a, b, **kwargs):
23572381
which can automatically choose the best kind of composite
23582382
transform instance to create.
23592383
"""
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)
23612390
self.input_dims = a.input_dims
23622391
self.output_dims = b.output_dims
2363-
assert a.is_affine
2364-
assert b.is_affine
23652392

23662393
Affine2DBase.__init__(self, **kwargs)
23672394
self._a = a
@@ -2436,8 +2463,8 @@ def __init__(self, boxin, boxout, **kwargs):
24362463
Create a new :class:`BboxTransform` that linearly transforms
24372464
points from *boxin* to *boxout*.
24382465
"""
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"
24412468

24422469
Affine2DBase.__init__(self, **kwargs)
24432470
self._boxin = boxin
@@ -2480,7 +2507,8 @@ def __init__(self, boxout, **kwargs):
24802507
Create a new :class:`BboxTransformTo` that linearly transforms
24812508
points from the unit bounding box to *boxout*.
24822509
"""
2483-
assert boxout.is_bbox
2510+
if not boxout.is_bbox:
2511+
raise ValueError("'boxout' must be bbox")
24842512

24852513
Affine2DBase.__init__(self, **kwargs)
24862514
self._boxout = boxout
@@ -2538,7 +2566,8 @@ class BboxTransformFrom(Affine2DBase):
25382566
is_separable = True
25392567

25402568
def __init__(self, boxin, **kwargs):
2541-
assert boxin.is_bbox
2569+
if not boxin.is_bbox:
2570+
raise ValueError("'boxin' must be bbox")
25422571

25432572
Affine2DBase.__init__(self, **kwargs)
25442573
self._boxin = boxin
@@ -2613,7 +2642,10 @@ def __init__(self, path, transform):
26132642
Create a new :class:`TransformedPath` from the given
26142643
:class:`~matplotlib.path.Path` and :class:`Transform`.
26152644
"""
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)
26172649
TransformNode.__init__(self)
26182650

26192651
self._path = path

0 commit comments

Comments
 (0)
0