Skip to content

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

Merged
merged 36 commits into from
Mar 22, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
873e91d
converted assert into exception
montefra May 13, 2014
b297f41
Exception type modified according to @pelson comment
montefra May 26, 2014
187f584
removed assert in `draw_artist` and `redraw_in_frame`
montefra May 26, 2014
34c6a5f
most asserts modified to ValueError
montefra May 26, 2014
0c1f9f7
All asserts substituted by ValueError
montefra May 28, 2014
4cfa781
method name explicitly written in the message
montefra May 28, 2014
aba9d99
Most asserts changed to ValueErrors. Two changed to warning
montefra May 28, 2014
8fbb652
c* files done
montefra May 30, 2014
5a45046
assert removed
montefra May 30, 2014
33fdabe
Asserts removed. Side effect: function to check that the inputs have …
montefra May 30, 2014
67bdfea
Asserts removed throughout the files m*
montefra Jun 3, 2014
531004c
Asserts removed throughout the files r*
montefra Jun 3, 2014
eaca138
SyntaxError from Travis corrected
montefra Jun 3, 2014
9e4b911
assert removed from files s*
montefra Jun 3, 2014
d12fbb8
asserts removed from t* file. test and tri directories ignored
montefra Jun 4, 2014
7f80628
asserts removed from [u-z]* files
montefra Jun 4, 2014
4fc36c6
the only assert in a python public function removed
montefra Jun 4, 2014
617b622
Bug introduced while getting rid of the asserts fixed
montefra Jun 18, 2014
2cbb326
typo fixed (broke building documentation)
montefra Mar 5, 2015
20966e9
pep8 fixed. plot_day_summary2 removed (retained by error when rebasing)
montefra Mar 5, 2015
96c733e
PEP8 fixed
montefra Mar 5, 2015
140210f
PEP8 fixed - image.py
montefra Mar 5, 2015
a2abc7b
PEP 8 fixed - mlab.py
montefra Mar 5, 2015
25cec22
PEP 8 fixed - patches.py
montefra Mar 5, 2015
06aedf7
PEP8 fixed - path.py
montefra Mar 5, 2015
77da3b6
PEP8 fixed - sankey.py
montefra Mar 5, 2015
95ae2cd
PEP8 fixed - spines.py, table.py
montefra Mar 5, 2015
b167c0c
test adapted to code change (AssertionError -> ValueError)
montefra Mar 5, 2015
f9792a9
fixed according to #3060 comment
montefra Mar 5, 2015
850178e
Two bugs in assert -> exception transformation fixed
montefra Mar 5, 2015
c0ebd4f
Typo fixed
montefra Mar 5, 2015
6b6d2de
Bug in assert -> exception transformation fixed
montefra Mar 5, 2015
088542e
Typo fixed
montefra Mar 5, 2015
41bf6b5
Modified according to @tacaswell comments
montefra Mar 16, 2015
7ea5c1a
fixed pep8 Travis failure
montefra Mar 16, 2015
d6c3c32
python2.6 string formatting. style more uniform
montefra Mar 22, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
asserts removed from t* file. test and tri directories ignored
  • Loading branch information
montefra committed Mar 4, 2015
commit d12fbb8b7b217fe967f6535993a40eb2b35a690d
19 changes: 11 additions & 8 deletions lib/matplotlib/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto on formatting.

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

Expand All @@ -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))
Copy link
Member

Choose a reason for hiding this comment

The 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
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion lib/matplotlib/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']")
Copy link
Member

Choose a reason for hiding this comment

The 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 [ foo | bar ]

self._unit = unit

def get_unit(self):
Expand Down
6 changes: 4 additions & 2 deletions lib/matplotlib/ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,8 @@ def set_powerlimits(self, lims):
greater than 1e4.
See also :meth:`set_scientific`.
'''
assert len(lims) == 2, "argument must be a sequence of length 2"
if len(lims) != 2:
raise ValueError("'lims' must be a sequence of length 2")
self._powerlimits = lims

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

def lt(self, x):
Expand Down
90 changes: 61 additions & 29 deletions lib/matplotlib/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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'"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whoops! looks like we forgot to add a raise here. This is fixed in #4458


# Convert to radians if desired
if not radians:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use () continuation not \

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)

Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or should be and

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above

msg = "'boxin' and 'boxout' must be bbox"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing a raise

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and not quite what this is testing (this is just testing that they are 'true-ish' not that they are bbox instances).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching the raise missing.

About the second comment: what do you mean with "true-ish". The if is actually testing that both instances have a is_bbox property, but I guess that then somewhere else the code is making use of some bbox method/property. Would you prefer something like this?

"'boxin' and 'boxout' must look like a bbox"

Any suggestion?

Copy link
Member

Choose a reason for hiding this comment

The 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
Expand Down Expand Up @@ -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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment re true-ish as above


Affine2DBase.__init__(self, **kwargs)
self._boxout = boxout
Expand Down Expand Up @@ -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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just testing 'true-ish'


Affine2DBase.__init__(self, **kwargs)
self._boxin = boxin
Expand Down Expand Up @@ -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
Expand Down