Skip to content
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

1141 | Validate canvas width, height #1183

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
5 changes: 5 additions & 0 deletions datashader/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1227,9 +1227,14 @@ def validate_ranges(self, x_range, y_range):
self.x_axis.validate(x_range)
self.y_axis.validate(y_range)

def validate_extend(self, width, height):
ianthomas23 marked this conversation as resolved.
Show resolved Hide resolved
if width == 0 or height == 0:
ianthomas23 marked this conversation as resolved.
Show resolved Hide resolved
raise ValueError("Invalid extend plot_width and plot_height must be bigger than 0")
ianthomas23 marked this conversation as resolved.
Show resolved Hide resolved

def validate(self):
"""Check that parameter settings are valid for this object"""
self.validate_ranges(self.x_range, self.y_range)
self.validate_extend(self.plot_width, self.plot_height)


def bypixel(source, canvas, glyph, agg, *, antialias=False):
Expand Down
15 changes: 15 additions & 0 deletions datashader/tests/test_dask.py
Original file line number Diff line number Diff line change
Expand Up @@ -1564,3 +1564,18 @@ def test_line_antialias_where(npartitions):
sol_where_min[j, i] = agg_where_min[j, i] = nan

assert_eq_ndarray(agg_where_min.data, sol_where_min)

ianthomas23 marked this conversation as resolved.
Show resolved Hide resolved
def test_canvas_extend():
ianthomas23 marked this conversation as resolved.
Show resolved Hide resolved

ianthomas23 marked this conversation as resolved.
Show resolved Hide resolved
cvs_list = [
ds.Canvas(plot_width=0, plot_height=6),
ds.Canvas(plot_width=5, plot_height=0),
ds.Canvas(plot_width=0, plot_height=0)
]
msg = r'Invalid extend plot_width and plot_height must be bigger than 0'
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
msg = r'Invalid extend plot_width and plot_height must be bigger than 0'
msg = r'Invalid size: plot_width and plot_height must be bigger than 0'

df = pd.DataFrame(dict(x=[0, 0.2, 1], y=[0, 0.4, 1], z=[10, 20, 30]))
ddf = dd.from_pandas(df, 1)
for cvs in cvs_list:
with pytest.raises(ValueError, match=msg):
cvs.points(ddf, "x", "y", ds.mean("z"))

17 changes: 17 additions & 0 deletions datashader/tests/test_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -2393,3 +2393,20 @@ def test_line_coordinate_lengths():
for ny in (1, 3):
with pytest.raises(ValueError, match=msg):
cvs.line(source=df, x=["x0", "x1"], y=np.arange(ny), axis=1)

ianthomas23 marked this conversation as resolved.
Show resolved Hide resolved


def test_canvas_extend():
ianthomas23 marked this conversation as resolved.
Show resolved Hide resolved

ianthomas23 marked this conversation as resolved.
Show resolved Hide resolved
cvs_list = [
ds.Canvas(plot_width=0, plot_height=6),
ds.Canvas(plot_width=5, plot_height=0),
ds.Canvas(plot_width=0, plot_height=0)
]
msg = r'Invalid extend plot_width and plot_height must be bigger than 0'
ianthomas23 marked this conversation as resolved.
Show resolved Hide resolved
df = pd.DataFrame(dict(x=[0, 0.2, 1], y=[0, 0.4, 1], z=[10, 20, 30]))

for cvs in cvs_list:
with pytest.raises(ValueError, match=msg):
cvs.points(df, "x", "y", ds.mean("z"))