Skip to content

Commit

Permalink
fix inexacterrors caused by type coercion in broadcast
Browse files Browse the repository at this point in the history
  • Loading branch information
tlnagy committed Aug 25, 2016
1 parent f6183ac commit 7c3590d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/statistics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1749,8 +1749,9 @@ function apply_statistic(stat::JitterStatistic,
rng = MersenneTwister(stat.seed)
for var in stat.vars
data = getfield(aes, var)
broadcast!(+, data, data, stat.range * (rand(rng, length(data)) - 0.5) .* span)
setfield!(aes, var, data)
outdata = Array(Float64, size(data))
broadcast!(+, outdata, data, stat.range * (rand(rng, length(data)) - 0.5) .* span)
setfield!(aes, var, outdata)
end
end

Expand Down
4 changes: 3 additions & 1 deletion test/jitter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ using Gadfly, DataArrays, RDatasets
plot(dataset("datasets", "iris"), x=:SepalLength, y=:SepalWidth, color=:Species,
Stat.x_jitter, Stat.y_jitter, Geom.point)


# make sure type-coercion works properly, the `y` values here are integers
# but will be coerced into floats.
plot(x=rand(500), y=rand(1:4, 500), Stat.y_jitter(range=0.5), Geom.point)

0 comments on commit 7c3590d

Please sign in to comment.