Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

combine() error with std() on GroupedDataFrame with Unitful columns #2600

Closed
tomyun opened this issue Jan 15, 2021 · 4 comments · Fixed by #2601
Closed

combine() error with std() on GroupedDataFrame with Unitful columns #2600

tomyun opened this issue Jan 15, 2021 · 4 comments · Fixed by #2601
Labels
Milestone

Comments

@tomyun
Copy link

tomyun commented Jan 15, 2021

using DataFrames, Statistics, Unitful
df = DataFrame(a=[:a, :a, :b, :b], b=[0, 1, 2, 3]u"m")
julia> combine(df, :b => std)
1×1 DataFrame
 Row │ b_std
     │ Quantity…
─────┼───────────
   1 │ 1.29099 m
julia> combine(groupby(df, :a), :b => std)
ERROR: DimensionError: 0.0 m and 0.25 m² are not dimensionally compatible.
Stacktrace:
 [1] +(::Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}}, ::Quantity{Float64,𝐋²,Unitful.FreeUnits{(m²,),𝐋²,nothing}}) at /Users/tomyun/.julia/packages/Unitful/1t88N/src/quantities.jl:137
 [2] groupreduce!(::Array{Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}},1}, ::DataFrames.var"#535#538"{Array{Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}},1}}, ::typeof(+), ::Nothing, ::Function, ::Bool, ::Array{Quantity{Int64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}},1}, ::GroupedDataFrame{DataFrame}) at /Users/tomyun/.julia/packages/DataFrames/yqToF/src/groupeddataframe/fastaggregates.jl:174
 [3] (::DataFrames.Aggregate{typeof(var),Nothing})(::Array{Quantity{Int64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}},1}, ::GroupedDataFrame{DataFrame}) at /Users/tomyun/.julia/packages/DataFrames/yqToF/src/groupeddataframe/fastaggregates.jl:248
 [4] (::DataFrames.Aggregate{typeof(std),Nothing})(::Array{Quantity{Int64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}},1}, ::GroupedDataFrame{DataFrame}) at /Users/tomyun/.julia/packages/DataFrames/yqToF/src/groupeddataframe/fastaggregates.jl:254
 [5] _combine_process_agg(::Pair{Int64,var"#s151"} where var"#s151"<:(Pair{var"#s150",Symbol} where var"#s150"<:Function), ::Bool, ::DataFrame, ::GroupedDataFrame{DataFrame}, ::Dict{Symbol,Tuple{Bool,Int64}}, ::Array{DataFrames.TransformationResult,1}, ::Array{Int64,1}) at /Users/tomyun/.julia/packages/DataFrames/yqToF/src/groupeddataframe/splitapplycombine.jl:203
 [6] _combine(::GroupedDataFrame{DataFrame}, ::Array{Any,1}, ::Array{Bool,1}, ::Bool, ::Bool, ::Bool) at /Users/tomyun/.julia/packages/DataFrames/yqToF/src/groupeddataframe/splitapplycombine.jl:532
 [7] _combine_prepare(::GroupedDataFrame{DataFrame}, ::Union{Regex, AbstractString, Function, Signed, Symbol, Unsigned, Pair, AbstractArray{T,1} where T, Type, All, Between, Cols, InvertedIndex}; keepkeys::Bool, ungroup::Bool, copycols::Bool, keeprows::Bool, renamecols::Bool) at /Users/tomyun/.julia/packages/DataFrames/yqToF/src/groupeddataframe/splitapplycombine.jl:66
 [8] #combine#509 at /Users/tomyun/.julia/packages/DataFrames/yqToF/src/groupeddataframe/splitapplycombine.jl:638 [inlined]
 [9] combine(::GroupedDataFrame{DataFrame}, ::Pair{Symbol,typeof(std)}) at /Users/tomyun/.julia/packages/DataFrames/yqToF/src/groupeddataframe/splitapplycombine.jl:638
 [10] top-level scope at REPL[16]:1

Tested on Julia 1.5.3 with DataFrames 0.22.2 and Unitful 1.5.0.

@bkamins bkamins added the bug label Jan 15, 2021
@bkamins bkamins added this to the 1.0 milestone Jan 15, 2021
@bkamins
Copy link
Member

bkamins commented Jan 15, 2021

@nalimilan - could you please have a look at it. It seems to be the problem with the fast path that you have implemented (if you do not have time I can check it - please let me know then).

@nalimilan
Copy link
Member

Good catch. This kind of thing is hard to get right until somebody actually tries it. I'll push a fix tomorrow.

@nalimilan
Copy link
Member

If you need a workaround in the meantime, note that combine(..., :b => (x -> std(x))) avoids the optimized method that fails.

@nalimilan
Copy link
Member

See #2601.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants