From 65b03a33e8a6e5ec8c918d3ccf9d76161701200e Mon Sep 17 00:00:00 2001 From: Jon Mease Date: Tue, 1 Oct 2019 14:32:47 -0400 Subject: [PATCH] Fix tests --- .../tests/benchmarks/test_extend_line.py | 24 ++++++++++------- datashader/tests/test_glyphs.py | 26 ++++++++++++------- datashader/tests/test_pandas.py | 2 +- 3 files changed, 32 insertions(+), 20 deletions(-) diff --git a/datashader/tests/benchmarks/test_extend_line.py b/datashader/tests/benchmarks/test_extend_line.py index 745fe68b9..751761a14 100644 --- a/datashader/tests/benchmarks/test_extend_line.py +++ b/datashader/tests/benchmarks/test_extend_line.py @@ -29,21 +29,23 @@ def append(i, x, y, agg): @pytest.mark.benchmark(group="extend_line") def test_extend_line_uniform(benchmark, extend_line, low, high): n = 10**6 - vt = (1, 0, 1, 0) - bounds = (0, 0, 10**4, 10**4) + sx, tx, sy, ty = (1, 0, 1, 0) + xmin, xmax, ymin, ymax = (0, 0, 10**4, 10**4) - xs = np.random.uniform(bounds[0] + low, bounds[2] + high, n) - ys = np.random.uniform(bounds[1] + low, bounds[3] + high, n) + xs = np.random.uniform(xmin + low, ymin + high, n) + ys = np.random.uniform(xmax + low, ymax + high, n) - agg = np.zeros((bounds[2], bounds[3]), dtype='i4') - benchmark(extend_line, vt, bounds, xs, ys, True, agg) + agg = np.zeros((ymin, ymax), dtype='i4') + benchmark( + extend_line, sx, tx, sy, ty, xmin, xmax, ymin, ymax, xs, ys, True, agg + ) @pytest.mark.benchmark(group="extend_line") def test_extend_line_normal(benchmark, extend_line): n = 10**6 - vt = (1, 0, 1, 0) - bounds = (0, 0, 10**4, 10**4) + sx, tx, sy, ty = (1, 0, 1, 0) + xmin, xmax, ymin, ymax = (0, 0, 10**4, 10**4) start = 1456297053 end = start + 60 * 60 * 24 @@ -53,5 +55,7 @@ def test_extend_line_normal(benchmark, extend_line): noise = lambda var, bias, n: np.random.normal(bias, var, n) ys = signal + noise(1, 10*(np.random.random() - 0.5), n) - agg = np.zeros((bounds[2], bounds[3]), dtype='i4') - benchmark(extend_line, vt, bounds, xs, ys, True, agg) + agg = np.zeros((ymin, ymax), dtype='i4') + benchmark( + extend_line, sx, tx, sy, ty, xmin, xmax, ymin, ymax, xs, ys, True, agg + ) diff --git a/datashader/tests/test_glyphs.py b/datashader/tests/test_glyphs.py index 596e31969..19ec79e0e 100644 --- a/datashader/tests/test_glyphs.py +++ b/datashader/tests/test_glyphs.py @@ -164,12 +164,14 @@ def test_extend_lines(): [0, 1, 0, 1, 0], [0, 0, 0, 0, 0]]) agg = new_agg() - extend_line(vt, bounds, xs, ys, False, agg) + sx, tx, sy, ty = vt + xmin, xmax, ymin, ymax = bounds + extend_line(sx, tx, sy, ty, xmin, xmax, ymin, ymax, xs, ys, False, agg) np.testing.assert_equal(agg, out) # plot_start = True out[2, 3] += 1 agg = new_agg() - extend_line(vt, bounds, xs, ys, True, agg) + extend_line(sx, tx, sy, ty, xmin, xmax, ymin, ymax, xs, ys, True, agg) np.testing.assert_equal(agg, out) xs = np.array([2, 1, 0, -1, -4, -1, -100, -1, 2]) @@ -180,7 +182,7 @@ def test_extend_lines(): [1, 1, 0, 1, 0], [0, 0, 0, 0, 0]]) agg = new_agg() - extend_line(vt, bounds, xs, ys, True, agg) + extend_line(sx, tx, sy, ty, xmin, xmax, ymin, ymax, xs, ys, True, agg) np.testing.assert_equal(agg, out) @@ -188,7 +190,9 @@ def test_extend_lines_all_out_of_bounds(): xs = np.array([-100, -200, -100]) ys = np.array([0, 0, 1]) agg = new_agg() - extend_line(vt, bounds, xs, ys, True, agg) + sx, tx, sy, ty = vt + xmin, xmax, ymin, ymax = bounds + extend_line(sx, tx, sy, ty, xmin, xmax, ymin, ymax, xs, ys, True, agg) assert agg.sum() == 0 @@ -196,7 +200,9 @@ def test_extend_lines_nan(): xs = np.array([-3, -2, np.nan, 0, 1]) ys = np.array([-3, -2, np.nan, 0, 1]) agg = new_agg() - extend_line(vt, bounds, xs, ys, True, agg) + sx, tx, sy, ty = vt + xmin, xmax, ymin, ymax = bounds + extend_line(sx, tx, sy, ty, xmin, xmax, ymin, ymax, xs, ys, True, agg) out = np.diag([1, 1, 0, 2, 0]) np.testing.assert_equal(agg, out) @@ -206,7 +212,9 @@ def test_extend_lines_exact_bounds(): ys = np.array([-3, -3, 1, 1, -3]) agg = np.zeros((4, 4), dtype='i4') - extend_line(vt, bounds, xs, ys, True, agg) + sx, tx, sy, ty = vt + xmin, xmax, ymin, ymax = bounds + extend_line(sx, tx, sy, ty, xmin, xmax, ymin, ymax, xs, ys, True, agg) out = np.array([[2, 1, 1, 1], [1, 0, 0, 1], [1, 0, 0, 1], @@ -214,7 +222,7 @@ def test_extend_lines_exact_bounds(): np.testing.assert_equal(agg, out) agg = np.zeros((4, 4), dtype='i4') - extend_line(vt, bounds, xs, ys, False, agg) + extend_line(sx, tx, sy, ty, xmin, xmax, ymin, ymax, xs, ys, False, agg) out = np.array([[1, 1, 1, 1], [1, 0, 0, 1], [1, 0, 0, 1], @@ -813,8 +821,8 @@ def test_line_awkward_point_on_upper_bound_maps_to_last_pixel(): assert y!=ymax np.testing.assert_almost_equal(y,ymax,decimal=6) - _,pymax = map_onto_pixel_for_line((1.0, 0.0, sy, 0.0), - (0.0, 1.0, 0.0, ymax), + _,pymax = map_onto_pixel_for_line(1.0, 0.0, sy, 0.0, + 0.0, 1.0, 0.0, ymax, 1.0, y) assert pymax==num_y_pixels-1 diff --git a/datashader/tests/test_pandas.py b/datashader/tests/test_pandas.py index bf96b98c0..466a93edf 100644 --- a/datashader/tests/test_pandas.py +++ b/datashader/tests/test_pandas.py @@ -76,7 +76,7 @@ def floats(n): def values(s): - if isinstance(s, cudf.Series): + if cudf and isinstance(s, cudf.Series): return s.to_array(fillna=np.nan) else: return s.values