GiovineItalia / Gadfly.jl

Crafty statistical graphics for Julia.
http://gadflyjl.org/stable/
Other
1.9k stars 250 forks source link

InexactError() with date_bar.jl #507

Open kbuzby opened 9 years ago

kbuzby commented 9 years ago

Pkg.test("Gadfly") failing due to an inexact error with the date_bar.jl test in v0.4

I've done some digging and this due to the span variable in geom/bar.jl trying to hold the value of a floating point Date type, but Date is only in Int.

I'm trying to figure out ways around this but the only thing I can see is to force the "values" item that span is working on to be Int type, I will test and update; however, I don't believe the tests will show if this forced conversion will cause any unwanted display of certain types of graphs.

Additionally, on a related note: why is span divided by (unique_count - 1), and not just unique_count?

UPDATE: forcing "values" to be Int still fails the tests; I'm still looking at ways that dates could be easily passed as integers without fully converting format to UTC or similar.

kbuzby commented 9 years ago

I've opened an issue in julia base to discuss the use of fractional dates which should solve this error if implemented.

amellnik commented 8 years ago

I came across this issue today. If anyone needs a simple example to reproduce:

using DataFrames, Gadfly
df = DataFrame(SeedsInApplesEaten = [ 2,5,5,3,4,4], Date = Date[Date(2015,1,i) for i in [1,1,1,2,2,2]])
plot(df, x=:Date, y=:SeedsInApplesEaten, Geom.boxplot)

A simple workaround is to covert the date to the unix time, plot against that, and then use a custom tick function to display the time in more helpful units:

df[:unixTime] = Float64[Dates.datetime2unix(DateTime(d)) for d in df[:Date]]
plot(df, x=:unixTime, y=:SeedsInApplesEaten, Geom.boxplot, Guide.xlabel("Date"),
Scale.x_continuous(labels = d -> string(Dates.Date(Dates.unix2datetime(d)))))
amellnik commented 8 years ago

Also note that this works for DateTime but not for Date at the moment.

using DataFrames, Gadfly
df = DataFrame(SeedsInApplesEaten = [ 2,5,5,3,4,4], Date = DateTime[DateTime(2015,1,i) for i in [1,1,1,2,2,2]])
plot(df, x=:Date, y=:SeedsInApplesEaten, Geom.boxplot)