From 37a0a8eb8ca109026c3c13b4fa6c976382c38ccb Mon Sep 17 00:00:00 2001 From: Joseph Crail Date: Thu, 27 Apr 2017 18:14:24 -0400 Subject: [PATCH] Adjust line to account for exclusive upper bounds When extending a line, I decremented the upper bounds for both x and y. Fix #328 --- datashader/glyphs.py | 3 +++ datashader/tests/test_dask.py | 2 +- datashader/tests/test_glyphs.py | 10 +++++----- datashader/tests/test_pandas.py | 2 +- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/datashader/glyphs.py b/datashader/glyphs.py index 97c3f6794..321cc3cf7 100644 --- a/datashader/glyphs.py +++ b/datashader/glyphs.py @@ -179,6 +179,9 @@ def extend_line(vt, bounds, xs, ys, plot_start, *aggs_and_cols): """Aggregate along a line formed by ``xs`` and ``ys``""" sx, tx, sy, ty = vt xmin, xmax, ymin, ymax = bounds + # Adjustments for exclusive upper bounds for x and y + xmax -= 1 + ymax -= 1 nrows = xs.shape[0] i = 0 while i < nrows - 1: diff --git a/datashader/tests/test_dask.py b/datashader/tests/test_dask.py index 90e88c417..c37254c74 100644 --- a/datashader/tests/test_dask.py +++ b/datashader/tests/test_dask.py @@ -179,7 +179,7 @@ def test_line(): [0, 1, 0, 0, 0, 1, 0], [1, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0], - [3, 0, 0, 0, 0, 0, 1], + [1, 0, 0, 0, 0, 0, 1], [0, 2, 0, 0, 0, 1, 0], [0, 0, 1, 0, 1, 0, 0]], dtype='i4') out = xr.DataArray(sol, coords=[np.arange(-3., 4.), np.arange(-3., 4.)], diff --git a/datashader/tests/test_glyphs.py b/datashader/tests/test_glyphs.py index b1a70c1a0..8d5256e5c 100644 --- a/datashader/tests/test_glyphs.py +++ b/datashader/tests/test_glyphs.py @@ -128,7 +128,7 @@ def test_extend_lines(): [0, 0, 0, 0, 0], [0, 1, 1, 1, 0], [0, 1, 0, 1, 0], - [0, 1, 0, 1, 0]]) + [0, 0, 0, 0, 0]]) agg = new_agg() extend_line(vt, bounds, xs, ys, False, agg) np.testing.assert_equal(agg, out) @@ -141,10 +141,10 @@ def test_extend_lines(): xs = np.array([2, 1, 0, -1, -4, -1, -100, -1, 2]) ys = np.array([-1, -2, -3, -4, -1, 2, 100, 2, -1]) out = np.array([[0, 1, 0, 1, 0], - [1, 0, 0, 0, 1], + [1, 0, 0, 0, 0], [0, 0, 0, 0, 0], - [1, 0, 0, 0, 1], - [0, 1, 0, 1, 0]]) + [1, 0, 0, 0, 0], + [0, 0, 0, 0, 0]]) agg = new_agg() extend_line(vt, bounds, xs, ys, True, agg) np.testing.assert_equal(agg, out) @@ -163,5 +163,5 @@ def test_extend_lines_nan(): ys = np.array([-3, -2, np.nan, 0, 1]) agg = new_agg() extend_line(vt, bounds, xs, ys, True, agg) - out = np.diag([1, 1, 0, 1, 1]) + out = np.diag([1, 1, 0, 1, 0]) np.testing.assert_equal(agg, out) diff --git a/datashader/tests/test_pandas.py b/datashader/tests/test_pandas.py index 3fa20dbbf..49706af33 100644 --- a/datashader/tests/test_pandas.py +++ b/datashader/tests/test_pandas.py @@ -172,7 +172,7 @@ def test_line(): [0, 1, 0, 0, 0, 1, 0], [1, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0], - [3, 0, 0, 0, 0, 0, 1], + [1, 0, 0, 0, 0, 0, 1], [0, 2, 0, 0, 0, 1, 0], [0, 0, 1, 0, 1, 0, 0]], dtype='i4') out = xr.DataArray(sol, coords=[np.arange(-3., 4.), np.arange(-3., 4.)],