Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jonmmease committed Oct 1, 2019
1 parent 3d9b8d5 commit 65b03a3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 20 deletions.
24 changes: 14 additions & 10 deletions datashader/tests/benchmarks/test_extend_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
)
26 changes: 17 additions & 9 deletions datashader/tests/test_glyphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -180,23 +182,27 @@ 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)


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


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)

Expand All @@ -206,15 +212,17 @@ 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],
[1, 1, 1, 1]])
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],
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion datashader/tests/test_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 65b03a3

Please sign in to comment.