-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
converted assert into exception #3060
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
873e91d
b297f41
187f584
34c6a5f
0c1f9f7
4cfa781
aba9d99
8fbb652
5a45046
33fdabe
67bdfea
531004c
eaca138
9e4b911
d12fbb8
7f80628
4fc36c6
617b622
2cbb326
20966e9
96c733e
140210f
a2abc7b
25cec22
06aedf7
77da3b6
95ae2cd
b167c0c
f9792a9
850178e
c0ebd4f
6b6d2de
088542e
41bf6b5
7ea5c1a
d6c3c32
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -154,7 +154,7 @@ class Table(Artist): | |
|
||
Each entry in the table can be either text or patches. | ||
|
||
Column widths and row heights for the table can be specifified. | ||
Column widths and row heights for the table can be specified. | ||
|
||
Return value is a sequence of text, line and patch instances that make | ||
up the table | ||
|
@@ -482,12 +482,17 @@ def table(ax, | |
rows = len(cellText) | ||
cols = len(cellText[0]) | ||
for row in cellText: | ||
assert len(row) == cols | ||
if len(row) != cols: | ||
msg = "Each row in 'cellText' must have {} columns" | ||
raise ValueError(msg.format(cols)) | ||
|
||
if cellColours is not None: | ||
assert len(cellColours) == rows | ||
if len(cellColours) != rows: | ||
raise ValueError("'cellColours' must have {} rows".format(rows)) | ||
for row in cellColours: | ||
assert len(row) == cols | ||
if len(row) != cols: | ||
msg = "Each row in 'cellColours' must have {} columns" | ||
raise ValueError(msg.format(cols)) | ||
else: | ||
cellColours = ['w' * cols] * rows | ||
|
||
|
@@ -506,7 +511,8 @@ def table(ax, | |
rowColours = 'w' * rows | ||
|
||
if rowLabels is not None: | ||
assert len(rowLabels) == rows | ||
if len(rowLabels) != rows: | ||
raise ValueError("'rowLabels' must be of length {}".format(rows)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto on formatting |
||
|
||
# If we have column labels, need to shift | ||
# the text and colour arrays down 1 row | ||
|
@@ -519,9 +525,6 @@ def table(ax, | |
elif colColours is None: | ||
colColours = 'w' * cols | ||
|
||
if rowLabels is not None: | ||
assert len(rowLabels) == rows | ||
|
||
# Set up cell colours if not given | ||
if cellColours is None: | ||
cellColours = ['w' * cols] * rows | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1474,7 +1474,8 @@ def __init__(self, artist, ref_coord, unit="points"): | |
self.set_unit(unit) | ||
|
||
def set_unit(self, unit): | ||
assert unit in ["points", "pixels"] | ||
if unit not in ["points", "pixels"]: | ||
raise ValueError("'unit' must be one of ['points', 'pixels']") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should probably make this consistent with the rest of the messages that ar |
||
self._unit = unit | ||
|
||
def get_unit(self): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -593,7 +593,8 @@ def shrunk_to_aspect(self, box_aspect, container=None, fig_aspect=1.0): | |
*fig_aspect*, so that *box_aspect* can also be given as a | ||
ratio of the absolute dimensions, not the relative dimensions. | ||
""" | ||
assert box_aspect > 0 and fig_aspect > 0 | ||
if box_aspect <= 0 or fig_aspect <= 0: | ||
raise ValueError("'box_aspect' and 'fig_aspect' must be positive") | ||
if container is None: | ||
container = self | ||
w, h = container.size | ||
|
@@ -719,7 +720,8 @@ def union(bboxes): | |
""" | ||
Return a :class:`Bbox` that contains all of the given bboxes. | ||
""" | ||
assert(len(bboxes)) | ||
if not len(bboxes): | ||
raise ValueError("'bboxes' cannot be empty") | ||
|
||
if len(bboxes) == 1: | ||
return bboxes[0] | ||
|
@@ -1062,10 +1064,15 @@ def __init__(self, bbox, transform, **kwargs): | |
|
||
*transform*: a 2D :class:`Transform` | ||
""" | ||
assert bbox.is_bbox | ||
assert isinstance(transform, Transform) | ||
assert transform.input_dims == 2 | ||
assert transform.output_dims == 2 | ||
if not bbox.is_bbox: | ||
raise ValueError("'bbox' is not a bbox") | ||
if not isinstance(transform, Transform): | ||
msg = "'transform' must be an instance of" | ||
msg += " 'matplotlib.transform.Transform'" | ||
raise ValueError(msg) | ||
if transform.input_dims != 2 or transform.output_dims != 2: | ||
msg = "The input and output dimensions of 'transform' must be 2" | ||
raise ValueError(msg) | ||
|
||
BboxBase.__init__(self, **kwargs) | ||
self._bbox = bbox | ||
|
@@ -1384,7 +1391,9 @@ def transform_point(self, point): | |
The transformed point is returned as a sequence of length | ||
:attr:`output_dims`. | ||
""" | ||
assert len(point) == self.input_dims | ||
if len(point) != self.input_dims: | ||
msg = "The length of 'point' must be 'self.input_dims'" | ||
raise ValueError(msg) | ||
return self.transform(np.asarray([point]))[0] | ||
|
||
def transform_path(self, path): | ||
|
@@ -1454,12 +1463,12 @@ def transform_angles(self, angles, pts, radians=False, pushoff=1e-5): | |
if self.input_dims != 2 or self.output_dims != 2: | ||
raise NotImplementedError('Only defined in 2D') | ||
|
||
# pts must be array with 2 columns for x,y | ||
assert pts.shape[1] == 2 | ||
if pts.shape[1] != 2: | ||
raise ValueError("'pts' must be array with 2 columns for x,y") | ||
|
||
# angles must be a column vector and have same number of | ||
# rows as pts | ||
assert np.prod(angles.shape) == angles.shape[0] == pts.shape[0] | ||
if angles.ndim!=1 or angles.shape[0] != pts.shape[0]: | ||
msg = "'angles' must be a column vector and have same number of" | ||
msg += " rows as 'pts'" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. whoops! looks like we forgot to add a |
||
|
||
# Convert to radians if desired | ||
if not radians: | ||
|
@@ -1516,7 +1525,10 @@ def __init__(self, child): | |
*child*: A class:`Transform` instance. This child may later | ||
be replaced with :meth:`set`. | ||
""" | ||
assert isinstance(child, Transform) | ||
if not isinstance(child, Transform): | ||
msg = "'child' must be an instance of" | ||
msg += " 'matplotlib.transform.Transform'" | ||
raise ValueError(msg) | ||
Transform.__init__(self) | ||
self.input_dims = child.input_dims | ||
self.output_dims = child.output_dims | ||
|
@@ -1571,8 +1583,11 @@ def set(self, child): | |
The new child must have the same number of input and output | ||
dimensions as the current child. | ||
""" | ||
assert child.input_dims == self.input_dims | ||
assert child.output_dims == self.output_dims | ||
if child.input_dims != self.input_dims or \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please use |
||
child.output_dims != self.output_dims: | ||
msg = "The new child must have the same number of input and output" | ||
msg += " dimensions as the current child." | ||
raise ValueError(msg) | ||
|
||
self._set(child) | ||
|
||
|
@@ -1822,7 +1837,10 @@ def set(self, other): | |
Set this transformation from the frozen copy of another | ||
:class:`Affine2DBase` object. | ||
""" | ||
assert isinstance(other, Affine2DBase) | ||
if not isinstance(other, Affine2DBase): | ||
msg = "'other' must be an instance of" | ||
msg += " 'matplotlib.transform.Affine2DBase'" | ||
raise ValueError(msg) | ||
self._mtx = other.get_matrix() | ||
self.invalidate() | ||
|
||
|
@@ -2152,10 +2170,13 @@ def __init__(self, x_transform, y_transform, **kwargs): | |
can determine automatically which kind of blended transform to | ||
create. | ||
""" | ||
assert x_transform.is_affine | ||
assert y_transform.is_affine | ||
assert x_transform.is_separable | ||
assert y_transform.is_separable | ||
is_affine = x_transform.is_affine and y_transform.is_affine | ||
is_separable = x_transform.is_separable and y_transform.is_separable | ||
is_correct = is_correct and is_separable | ||
if not is_correct: | ||
msg = "Both *x_transform* and *y_transform* must be 2D affine" | ||
msg += " transforms." | ||
raise ValueError(msg) | ||
|
||
Transform.__init__(self, **kwargs) | ||
self._x = x_transform | ||
|
@@ -2232,7 +2253,10 @@ def __init__(self, a, b, **kwargs): | |
which can automatically choose the best kind of composite | ||
transform instance to create. | ||
""" | ||
assert a.output_dims == b.input_dims | ||
if a.output_dims != b.input_dims: | ||
msg = "The output dimension of 'a' must be equal to the input" | ||
msg += " dimensions of 'b'" | ||
raise ValueError(msg) | ||
self.input_dims = a.input_dims | ||
self.output_dims = b.output_dims | ||
|
||
|
@@ -2357,11 +2381,14 @@ def __init__(self, a, b, **kwargs): | |
which can automatically choose the best kind of composite | ||
transform instance to create. | ||
""" | ||
assert a.output_dims == b.input_dims | ||
if not a.is_affine or not b.is_affine: | ||
raise ValueError("'a' and 'b' must be affine transforms") | ||
if a.output_dims != b.input_dims: | ||
msg = "The output dimension of 'a' must be equal to the input" | ||
msg += " dimensions of 'b'" | ||
raise ValueError(msg) | ||
self.input_dims = a.input_dims | ||
self.output_dims = b.output_dims | ||
assert a.is_affine | ||
assert b.is_affine | ||
|
||
Affine2DBase.__init__(self, **kwargs) | ||
self._a = a | ||
|
@@ -2436,8 +2463,8 @@ def __init__(self, boxin, boxout, **kwargs): | |
Create a new :class:`BboxTransform` that linearly transforms | ||
points from *boxin* to *boxout*. | ||
""" | ||
assert boxin.is_bbox | ||
assert boxout.is_bbox | ||
if not boxin.is_bbox or not boxout.is_bbox: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see above |
||
msg = "'boxin' and 'boxout' must be bbox" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for catching the About the second comment: what do you mean with "true-ish". The
Any suggestion? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am wrong here too, disregard those comments. |
||
|
||
Affine2DBase.__init__(self, **kwargs) | ||
self._boxin = boxin | ||
|
@@ -2480,7 +2507,8 @@ def __init__(self, boxout, **kwargs): | |
Create a new :class:`BboxTransformTo` that linearly transforms | ||
points from the unit bounding box to *boxout*. | ||
""" | ||
assert boxout.is_bbox | ||
if not boxout.is_bbox: | ||
raise ValueError("'boxout' must be bbox") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
Affine2DBase.__init__(self, **kwargs) | ||
self._boxout = boxout | ||
|
@@ -2538,7 +2566,8 @@ class BboxTransformFrom(Affine2DBase): | |
is_separable = True | ||
|
||
def __init__(self, boxin, **kwargs): | ||
assert boxin.is_bbox | ||
if not boxin.is_bbox: | ||
raise ValueError("'boxin' must be bbox") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
Affine2DBase.__init__(self, **kwargs) | ||
self._boxin = boxin | ||
|
@@ -2613,7 +2642,10 @@ def __init__(self, path, transform): | |
Create a new :class:`TransformedPath` from the given | ||
:class:`~matplotlib.path.Path` and :class:`Transform`. | ||
""" | ||
assert isinstance(transform, Transform) | ||
if not isinstance(transform, Transform): | ||
msg = "'transform' must be an instance of" | ||
msg += " 'matplotlib.transform.Transform'" | ||
raise ValueError(msg) | ||
TransformNode.__init__(self) | ||
|
||
self._path = path | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto on formatting.