support Unitful.jl
bjarthur opened this issue Β· comments
Ben Arthur commented
would be nice if this worked:
julia> using Unitful, StatsBase
julia> fit(Histogram, (1:1000)u"s", (0:100:1000)u"s")
ERROR: MethodError: no method matching push!(::Histogram{Int64, 1, Tuple{StepRange{Quantity{Int64, π, Unitful.FreeUnits{(s,), π, nothing}}, Quantity{Int64, π, Unitful.FreeUnits{(s,), π, nothing}}}}}, ::Tuple{Quantity{Int64, π, Unitful.FreeUnits{(s,), π, nothing}}})
Closest candidates are:
push!(::Any, ::Any, ::Any) at abstractarray.jl:3059
push!(::Any, ::Any, ::Any, ::Any...) at abstractarray.jl:3060
push!(::DataStructures.CircularBuffer, ::Any) at /groups/scicompsoft/home/arthurb/.julia/packages/DataStructures/59MD0/src/circular_buffer.jl:83
...
Stacktrace:
[1] push!(A::Histogram{Int64, 1, Tuple{StepRange{Quantity{Int64, π, Unitful.FreeUnits{(s,), π, nothing}}, Quantity{Int64, π, Unitful.FreeUnits{(s,), π, nothing}}}}}, a::Tuple{Quantity{Int64, π, Unitful.FreeUnits{(s,), π, nothing}}}, b::Int64)
@ Base ./abstractarray.jl:3059
[2] append!(h::Histogram{Int64, 1, Tuple{StepRange{Quantity{Int64, π, Unitful.FreeUnits{(s,), π, nothing}}, Quantity{Int64, π, Unitful.FreeUnits{(s,), π, nothing}}}}}, vs::Tuple{StepRange{Quantity{Int64, π, Unitful.FreeUnits{(s,), π, nothing}}, Quantity{Int64, π, Unitful.FreeUnits{(s,), π, nothing}}}})
@ StatsBase /groups/scicompsoft/home/arthurb/.julia/packages/StatsBase/XgjIN/src/hist.jl:334
[3] #fit#162
@ /groups/scicompsoft/home/arthurb/.julia/packages/StatsBase/XgjIN/src/hist.jl:353 [inlined]
[4] #fit#155
@ /groups/scicompsoft/home/arthurb/.julia/packages/StatsBase/XgjIN/src/hist.jl:298 [inlined]
[5] fit
@ /groups/scicompsoft/home/arthurb/.julia/packages/StatsBase/XgjIN/src/hist.jl:298 [inlined]
[6] #fit#166
@ /groups/scicompsoft/home/arthurb/.julia/packages/StatsBase/XgjIN/src/hist.jl:407 [inlined]
[7] fit(::Type{Histogram}, ::StepRange{Quantity{Int64, π, Unitful.FreeUnits{(s,), π, nothing}}, Quantity{Int64, π, Unitful.FreeUnits{(s,), π, nothing}}}, ::StepRange{Quantity{Int64, π, Unitful.FreeUnits{(s,), π, nothing}}, Quantity{Int64, π, Unitful.FreeUnits{(s,), π, nothing}}})
@ StatsBase /groups/scicompsoft/home/arthurb/.julia/packages/StatsBase/XgjIN/src/hist.jl:407
[8] top-level scope
@ REPL[4]:1
and gave the same answer as without the units:
julia> fit(Histogram, (1:1000), (0:100:1000))
Histogram{Int64, 1, Tuple{StepRange{Int64, Int64}}}
edges:
0:100:1000
weights: [99, 100, 100, 100, 100, 100, 100, 100, 100, 100]
closed: left
isdensity: false