Skip to content

Commit

Permalink
Trac #33479: adjust error messages in plot/
Browse files Browse the repository at this point in the history
same as #33367

also some whitespace removal in plot/

URL: https://trac.sagemath.org/33479
Reported by: chapoton
Ticket author(s): Frédéric Chapoton
Reviewer(s): Matthias Koeppe
  • Loading branch information
Release Manager committed Mar 8, 2022
2 parents 7197367 + 920275f commit 64cca20
Show file tree
Hide file tree
Showing 21 changed files with 66 additions and 71 deletions.
2 changes: 1 addition & 1 deletion src/sage/plot/arc.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def __init__(self, x, y, r1, r2, angle, s1, s2, options):
self.r1 = float(r1)
self.r2 = float(r2)
if self.r1 <= 0 or self.r2 <= 0:
raise ValueError("the radii must be positive real numbers.")
raise ValueError("the radii must be positive real numbers")

self.angle = float(angle)
self.s1 = float(s1)
Expand Down
6 changes: 3 additions & 3 deletions src/sage/plot/arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def _render_on_subplot(self, subplot):
elif head == 2:
style = '<|-|>'
else:
raise KeyError('head parameter must be one of 0 (start), 1 (end) or 2 (both).')
raise KeyError('head parameter must be one of 0 (start), 1 (end) or 2 (both)')
arrowsize = float(options.get('arrowsize', 5))
head_width = arrowsize
head_length = arrowsize * 2.0
Expand Down Expand Up @@ -368,7 +368,7 @@ def _render_on_subplot(self, subplot):
elif head == 2:
style = '<|-|>'
else:
raise KeyError('head parameter must be one of 0 (start), 1 (end) or 2 (both).')
raise KeyError('head parameter must be one of 0 (start), 1 (end) or 2 (both)')
width = float(options['width'])
arrowshorten_end = float(options.get('arrowshorten', 0)) / 2.0
arrowsize = float(options.get('arrowsize', 5))
Expand Down Expand Up @@ -643,7 +643,7 @@ def arrow2d(tailpoint=None, headpoint=None, path=None, **options):
elif tailpoint is None and headpoint is None:
return g
else:
raise TypeError('Arrow requires either both headpoint and tailpoint or a path parameter.')
raise TypeError('arrow requires either both headpoint and tailpoint or a path parameter')
if options['legend_label']:
g.legend(True)
g._legend_colors = [options['legend_color']]
Expand Down
7 changes: 3 additions & 4 deletions src/sage/plot/bezier_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def _plot3d_options(self, options=None):
sage: B._plot3d_options()
Traceback (most recent call last):
...
NotImplementedError: Invalid 3d line style: 'dashed'
NotImplementedError: invalid 3d line style: 'dashed'
sage: B = BezierPath([[(0,0),(.5,.5),(1,0)],[(.5,1),(0,0)]], {'fill':False, 'thickness':2})
sage: B._plot3d_options()
{'thickness': 2}
Expand All @@ -146,11 +146,11 @@ def _plot3d_options(self, options=None):
del options['thickness']
if 'fill' in options:
if options['fill']:
raise NotImplementedError("Invalid 3d fill style. Must set fill to False.")
raise NotImplementedError("invalid 3d fill style; must set fill to False")
del options['fill']
if 'linestyle' in options:
if options['linestyle'] not in ('solid', '-'):
raise NotImplementedError("Invalid 3d line style: '%s'" %
raise NotImplementedError("invalid 3d line style: '%s'" %
(options['linestyle']))
del options['linestyle']
options_3d.update(GraphicPrimitive_xydata._plot3d_options(self, options))
Expand Down Expand Up @@ -393,7 +393,6 @@ def bezier_path(path, **options):
sage: foo = bezier_path(bp)
sage: bp
[[(1, 1), (2, 3), (3, 3)], [(4, 4), (5, 5)]]
"""
from sage.plot.all import Graphics
g = Graphics()
Expand Down
6 changes: 3 additions & 3 deletions src/sage/plot/circle.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ def circle(center, radius, **options):
sage: circle((1,1,1,1), 1, rgbcolor=(1,0,0))
Traceback (most recent call last):
...
ValueError: The center of a plotted circle should have two or three coordinates.
ValueError: the center of a plotted circle should have two or three coordinates
The default aspect ratio for a circle is 1.0::
Expand Down Expand Up @@ -420,5 +420,5 @@ def circle(center, radius, **options):
return g
elif len(center) == 3:
return g[0].plot3d(z=center[2])
else:
raise ValueError('The center of a plotted circle should have two or three coordinates.')
raise ValueError('the center of a plotted circle should have '
'two or three coordinates')
6 changes: 3 additions & 3 deletions src/sage/plot/disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ def disk(point, radius, angle, **options):
sage: d = disk((1,1,1,1), 1, (0,pi))
Traceback (most recent call last):
...
ValueError: The center point of a plotted disk should have two or three coordinates.
ValueError: the center point of a plotted disk should have two or three coordinates
"""
from sage.plot.all import Graphics
g = Graphics()
Expand All @@ -356,5 +356,5 @@ def disk(point, radius, angle, **options):
return g
elif len(point) == 3:
return g[0].plot3d(z=point[2])
else:
raise ValueError('The center point of a plotted disk should have two or three coordinates.')
raise ValueError('the center point of a plotted disk should have '
'two or three coordinates')
32 changes: 16 additions & 16 deletions src/sage/plot/ellipse.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Ellipses
"""
#*****************************************************************************
# ****************************************************************************
# Copyright (C) 2010 Vincent Delecroix <20100.delecroix@gmail.com>
#
# Distributed under the terms of the GNU General Public License (GPL)
Expand All @@ -13,8 +13,8 @@
#
# The full text of the GPL is available at:
#
# http://www.gnu.org/licenses/
#*****************************************************************************
# https://www.gnu.org/licenses/
# ****************************************************************************

from .primitive import GraphicPrimitive
from sage.misc.decorators import options, rename_keyword
Expand Down Expand Up @@ -273,37 +273,37 @@ def ellipse(center, r1, r2, angle=0, **options):
Graphics object consisting of 1 graphics primitive
.. PLOT::
E=ellipse((0,0),2,1)
sphinx_plot(E)
More complicated examples with tilted axes and drawing options::
sage: ellipse((0,0),3,1,pi/6,fill=True,alpha=0.3,linestyle="dashed")
Graphics object consisting of 1 graphics primitive
.. PLOT::
E = ellipse((0,0),3,1,pi/6,fill=True,alpha=0.3,linestyle="dashed")
sphinx_plot(E)
other way to indicate dashed linestyle::
sage: ellipse((0,0),3,1,pi/6,fill=True,alpha=0.3,linestyle="--")
Graphics object consisting of 1 graphics primitive
.. PLOT::
E =ellipse((0,0),3,1,pi/6,fill=True,alpha=0.3,linestyle='--')
sphinx_plot(E)
with colors ::
sage: ellipse((0,0),3,1,pi/6,fill=True,edgecolor='black',facecolor='red')
Graphics object consisting of 1 graphics primitive
.. PLOT::
E=ellipse((0,0),3,1,pi/6,fill=True,edgecolor='black',facecolor='red')
sphinx_plot(E)
Expand All @@ -312,9 +312,9 @@ def ellipse(center, r1, r2, angle=0, **options):
sage: ellipse((0,0),3,1,pi/6,fill=True,edgecolor='black',facecolor='red',rgbcolor='green')
Graphics object consisting of 1 graphics primitive
.. PLOT::
E=ellipse((0,0),3,1,pi/6,fill=True,edgecolor='black',facecolor='red',rgbcolor='green')
sphinx_plot(E)
Expand All @@ -334,12 +334,12 @@ def ellipse(center, r1, r2, angle=0, **options):
sage: ellipse((0,0),2,1,legend_label="My ellipse", legend_color='green')
Graphics object consisting of 1 graphics primitive
.. PLOT::
E=ellipse((0,0),2,1,legend_label="My ellipse", legend_color='green')
sphinx_plot(E)
"""
from sage.plot.all import Graphics
g = Graphics()
Expand Down
1 change: 0 additions & 1 deletion src/sage/plot/hyperbolic_arc.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,4 +401,3 @@ def hyperbolic_arc(a, b, model="UHP", **options):
g = g + circle((0, 0), 1, axes=False, color='black')
g.set_aspect_ratio(1)
return g

1 change: 0 additions & 1 deletion src/sage/plot/hyperbolic_polygon.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,4 +412,3 @@ def hyperbolic_triangle(a, b, c, model="UHP", **options):
"""
return hyperbolic_polygon((a, b, c), model, **options)

3 changes: 1 addition & 2 deletions src/sage/plot/hyperbolic_regular_polygon.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def __init__(self, sides, i_angle, center, options):
h_disp = self.center.real()

d_z_k = [z_0[0]*scale + h_disp] #d_k has the points for the polygon in the given center
z_k = z_0 #z_k has the Re(z)>0 vertices for the I centered polygon
z_k = z_0 #z_k has the Re(z)>0 vertices for the I centered polygon
r_z_k = [] #r_z_k has the Re(z)<0 vertices
if is_odd(self.sides):
vert = (self.sides - 1) // 2
Expand Down Expand Up @@ -292,4 +292,3 @@ def hyperbolic_regular_polygon(sides, i_angle, center=CC(0,1), **options):
g.add_primitive(HyperbolicRegularPolygon(sides, i_angle, center, options))
g.set_aspect_ratio(1)
return g

6 changes: 3 additions & 3 deletions src/sage/plot/line.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __init__(self, xdata, ydata, options):
valid_options = self._allowed_options()
for opt in options:
if opt not in valid_options:
raise RuntimeError("Error in line(): option '%s' not valid." % opt)
raise RuntimeError("error in line(): option '%s' not valid" % opt)
self.xdata = xdata
self.ydata = ydata
GraphicPrimitive_xydata.__init__(self, options)
Expand Down Expand Up @@ -107,7 +107,7 @@ def _plot3d_options(self, options=None):
sage: L.plot3d()
Traceback (most recent call last):
...
NotImplementedError: Invalid 3d line style: ':'
NotImplementedError: invalid 3d line style: ':'
"""
if options is None:
options = dict(self.options())
Expand All @@ -119,7 +119,7 @@ def _plot3d_options(self, options=None):
del options['zorder']
if 'linestyle' in options:
if options['linestyle'] not in ('-', 'solid'):
raise NotImplementedError("Invalid 3d line style: '%s'" %
raise NotImplementedError("invalid 3d line style: '%s'" %
(options['linestyle']))
del options['linestyle']
options_3d.update(GraphicPrimitive_xydata._plot3d_options(self, options))
Expand Down
4 changes: 2 additions & 2 deletions src/sage/plot/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -1916,7 +1916,7 @@ def f(x): return (floor(x)+0.5) / (1-(x-0.5)**2)
sage: P = plot(sin(1/x), (x,-1,3), foo=10)
Traceback (most recent call last):
...
RuntimeError: Error in line(): option 'foo' not valid.
RuntimeError: error in line(): option 'foo' not valid
sage: P = plot(x, (x,1,1)) # trac ticket #11753
Traceback (most recent call last):
...
Expand Down Expand Up @@ -3057,7 +3057,7 @@ def list_plot(data, plotjoined=False, **kwargs):
try:
if not data:
return Graphics()
except ValueError: # numpy raises ValueError if it is not empty
except ValueError: # numpy raises ValueError if it is not empty
pass
if not isinstance(plotjoined, bool):
raise TypeError("The second argument 'plotjoined' should be boolean "
Expand Down
2 changes: 1 addition & 1 deletion src/sage/plot/plot3d/index_face_set.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1793,7 +1793,7 @@ cdef class EdgeIter:
def __init__(self, face_set):
self.set = face_set
if not self.set.enclosed:
raise TypeError("Must be closed to use the simple iterator.")
raise TypeError("must be closed to use the simple iterator")
self.i = 0
self.j = 0
self.seen = {}
Expand Down
8 changes: 4 additions & 4 deletions src/sage/plot/plot3d/parametric_surface.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -384,13 +384,13 @@ cdef class ParametricSurface(IndexFaceSet):
sage: M.dual()
Traceback (most recent call last):
...
NotImplementedError: This is only implemented for enclosed surfaces
NotImplementedError: this is only implemented for enclosed surfaces
"""
# This doesn't completely make sense...
if self.fcount == 0:
self.triangulate()
if not self.is_enclosed():
raise NotImplementedError("This is only implemented for enclosed surfaces")
raise NotImplementedError("this is only implemented for enclosed surfaces")
return IndexFaceSet.dual(self)

def bounding_box(self):
Expand Down Expand Up @@ -585,10 +585,10 @@ cdef class ParametricSurface(IndexFaceSet):
sage: P.get_grid(.1)
Traceback (most recent call last):
...
NotImplementedError: You must override the get_grid method.
NotImplementedError: you must override the get_grid method
"""
if self.render_grid is None:
raise NotImplementedError("You must override the get_grid method.")
raise NotImplementedError("you must override the get_grid method")
return self.render_grid

cdef int eval_grid(self, urange, vrange) except -1:
Expand Down
4 changes: 2 additions & 2 deletions src/sage/plot/plot3d/platonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,12 +386,12 @@ def cube(center=(0, 0, 0), size=1, color=None, frame_thickness=0,
sage: cube(center=(10, 10, 10), size=0.5).bounding_box()
((9.75, 9.75, 9.75), (10.25, 10.25, 10.25))
AUTHORS:
- William Stein
"""
if isinstance(color, (list, tuple)) and len(color) > 0 and isinstance(color[0], (list,tuple,str)):
if isinstance(color, (list, tuple)) and len(color) > 0 and isinstance(color[0], (list, tuple, str)):
B = ColorCube(size=[0.5,0.5,0.5], colors=color, **kwds)
else:
if color is not None:
Expand Down
4 changes: 2 additions & 2 deletions src/sage/plot/plot3d/revolution_plot3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def cf(u, phi): return float(2 * u / pi) % 1
from sage.functions.trig import atan2

if parallel_axis not in ['x', 'y', 'z']:
raise ValueError("parallel_axis must be either 'x', 'y', or 'z'.")
raise ValueError("parallel_axis must be either 'x', 'y', or 'z'")

vart = trange[0]

Expand All @@ -232,7 +232,7 @@ def cf(u, phi): return float(2 * u / pi) % 1
phi = phirange[0]
else:
phirange = (phi, phirange[0], phirange[1])

if isinstance(curve, (tuple, list)):
#this if-else provides a vector v to be plotted
#if curve is a tuple or a list of length 2, it is interpreted as a parametric curve
Expand Down
9 changes: 5 additions & 4 deletions src/sage/plot/plot3d/shapes2.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,14 +426,15 @@ def frame_labels(lower_left, upper_right,
sage: frame_labels([1,2,3],[4,5,6],[1,2,3],[1,3,4])
Traceback (most recent call last):
...
ValueError: Ensure the upper right labels are above and to the right of the lower left labels.
ValueError: ensure the upper right labels are above and to the right of the lower left labels
"""
x0,y0,z0 = lower_left
x1,y1,z1 = upper_right
lx0,ly0,lz0 = label_lower_left
lx1,ly1,lz1 = label_upper_right
if (lx1 - lx0) <= 0 or (ly1 - ly0) <= 0 or (lz1 - lz0) <= 0:
raise ValueError("Ensure the upper right labels are above and to the right of the lower left labels.")
raise ValueError("ensure the upper right labels are above "
"and to the right of the lower left labels")

# Helper function for formatting the frame labels
from math import log
Expand Down Expand Up @@ -523,7 +524,7 @@ def ruler(start, end, ticks=4, sub_ticks=4, absolute=False, snap=False, **kwds):
sage: ruler([1,2,3],vector([1,3,4]),absolute=True)
Traceback (most recent call last):
...
ValueError: Absolute rulers only valid for axis-aligned paths
ValueError: absolute rulers only valid for axis-aligned paths
"""
start = vector(RDF, start)
end = vector(RDF, end)
Expand Down Expand Up @@ -552,7 +553,7 @@ def ruler(start, end, ticks=4, sub_ticks=4, absolute=False, snap=False, **kwds):

if absolute:
if dir[0]*dir[1] or dir[1]*dir[2] or dir[0]*dir[2]:
raise ValueError("Absolute rulers only valid for axis-aligned paths")
raise ValueError("absolute rulers only valid for axis-aligned paths")
m = max(dir[0], dir[1], dir[2])
if dir[0] == m:
off = start[0]
Expand Down
Loading

0 comments on commit 64cca20

Please sign in to comment.