Skip to content

Commit

Permalink
Merge pull request #885 from tlnagy/fix-broadcast-type-coercion
Browse files Browse the repository at this point in the history
fix inexacterrors caused by type coercion in broadcast
  • Loading branch information
shashi committed Aug 28, 2016
2 parents f6183ac + 7c3590d commit 1196f07
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 1196f07

Please sign in to comment.