# Query.jl @group DataFrame by AbstractType gives Method Error

**URL:** <https://discourse.julialang.org/t/query-jl-group-dataframe-by-abstracttype-gives-method-error/15501>\
**Category:** Data\
**Tags:** question\
**Created:** [September 26, 2018, 7:37am UTC](https://discourse.julialang.org/t/query-jl-group-dataframe-by-abstracttype-gives-method-error/15501 "2018-09-26T07:37:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![JonasIsensee](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jonasisensee/32/4704_2.png) [@JonasIsensee](https://discourse.julialang.org/u/JonasIsensee)\
**Post date:** [September 26, 2018, 7:37am UTC](https://discourse.julialang.org/t/query-jl-group-dataframe-by-abstracttype-gives-method-error/15501/1 "2018-09-26T07:37:36Z")

</div>

Hey there,

I noticed that it is not possible to `@group` by an abstract typed column  
and I’m wondering if this is deliberately so or just a bug.

```julia
julia> df = DataFrame(foo=Real[])
0×1 DataFrame

julia> push!(df, Dict(:foo => 1)); push!(df, Dict(:foo => 1.))
2×1 DataFrame
│ Row │ foo │
├─────┼─────┤
│ 1 │ 1 │
│ 2 │ 1.0 │

julia> grouped_df = @from i in df begin
           @group i by i.foo into g
           @select {foo=key(g)}
           @collect DataFrame
       end
ERROR: MethodError: Cannot `convert` an object of type QueryOperators.EnumerableMap{Any,QueryOperators.EnumerableGroupBySimple{Grouping{Real,NamedTuple{(:foo,),Tuple{Real}}},Real,NamedTuple{(:foo,),Tuple{Real}},QueryOperators.EnumerableIterable{NamedTuple{(:foo,),Tuple{Real}},TableTraitsUtils.TableIterator{NamedTuple{(:foo,),Tuple{Real}},Tuple{Array{Real,1}}}},getfield(Main, Symbol("##37#39"))},getfield(Main, Symbol("##38#40"))} to an object of type DataFrame
Closest candidates are:
  convert(::Type{DataFrame}, ::AbstractArray{T,2} where T) at /home/jonas/.julia/packages/DataFrames/utxEh/src/dataframe/dataframe.jl:986
  convert(::Type{DataFrame}, ::AbstractDict) at /home/jonas/.julia/packages/DataFrames/utxEh/src/dataframe/dataframe.jl:988
  convert(::Type{S}, ::T<:(Union{CategoricalString{R}, CategoricalValue{T,R} where T} where R)) where {S, T<:(Union{CategoricalString{R}, CategoricalValue{T,R} where T} where R)} at /home/jonas/.julia/packages/CategoricalArrays/04bks/src/value.jl:66
  ...
Stacktrace:
 [1] DataFrame(::QueryOperators.EnumerableMap{Any,QueryOperators.EnumerableGroupBySimple{Grouping{Real,NamedTuple{(:foo,),Tuple{Real}}},Real,NamedTuple{(:foo,),Tuple{Real}},QueryOperators.EnumerableIterable{NamedTuple{(:foo,),Tuple{Real}},TableTraitsUtils.TableIterator{NamedTuple{(:foo,),Tuple{Real}},Tuple{Array{Real,1}}}},getfield(Main, Symbol("##37#39"))},getfield(Main, Symbol("##38#40"))}) at /home/jonas/.julia/packages/IterableTables/Jkq8l/src/integrations/dataframes.jl:24
 [2] collect(::QueryOperators.EnumerableMap{Any,QueryOperators.EnumerableGroupBySimple{Grouping{Real,NamedTuple{(:foo,),Tuple{Real}}},Real,NamedTuple{(:foo,),Tuple{Real}},QueryOperators.EnumerableIterable{NamedTuple{(:foo,),Tuple{Real}},TableTraitsUtils.TableIterator{NamedTuple{(:foo,),Tuple{Real}},Tuple{Array{Real,1}}}},getfield(Main, Symbol("##37#39"))},getfield(Main, Symbol("##38#40"))}, ::Type{DataFrame}) at /home/jonas/.julia/packages/Query/fzgEu/src/sinks/sink_type.jl:2
 [3] top-level scope at none:0

```

The same thing works if I remove the type and do `df = DataFrame(foo=[])`.

---

<div class="post-metadata">

**Author:** ![davidanthoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidanthoff/32/223493_2.png) [@davidanthoff](https://discourse.julialang.org/u/davidanthoff)\
**Post date:** [November 12, 2018, 7:16pm UTC](https://discourse.julialang.org/t/query-jl-group-dataframe-by-abstracttype-gives-method-error/15501/2 "2018-11-12T19:16:03Z")

</div>

That looks like a bug to me, tracking it [here](https://github.com/queryverse/Query.jl/issues/214). Thanks for reporting!
