diff --git a/datashader/core.py b/datashader/core.py index 5f175281b..dae1f60a0 100644 --- a/datashader/core.py +++ b/datashader/core.py @@ -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_size(self, width, height): + if width <= 0 or height <= 0: + raise ValueError("Invalid size: plot_width and plot_height must be bigger than 0") + def validate(self): """Check that parameter settings are valid for this object""" self.validate_ranges(self.x_range, self.y_range) + self.validate_size(self.plot_width, self.plot_height) def bypixel(source, canvas, glyph, agg, *, antialias=False): diff --git a/datashader/tests/test_dask.py b/datashader/tests/test_dask.py index bf8a53f8d..57ebc721f 100644 --- a/datashader/tests/test_dask.py +++ b/datashader/tests/test_dask.py @@ -1564,3 +1564,21 @@ 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) + + +def test_canvas_size(): + 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), + ds.Canvas(plot_width=-1, plot_height=1), + ds.Canvas(plot_width=10, plot_height=-1) + ] + 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")) + \ No newline at end of file diff --git a/datashader/tests/test_pandas.py b/datashader/tests/test_pandas.py index cdb21315c..6eec931a4 100644 --- a/datashader/tests/test_pandas.py +++ b/datashader/tests/test_pandas.py @@ -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) + + +def test_canvas_size(): + 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), + ds.Canvas(plot_width=-1, plot_height=1), + ds.Canvas(plot_width=10, plot_height=-1) + ] + 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])) + + for cvs in cvs_list: + with pytest.raises(ValueError, match=msg): + cvs.points(df, "x", "y", ds.mean("z")) + \ No newline at end of file