Query.@orderby destroys DataFrame

This code does not work:

using DataFrames, Query
df = DataFrame(A=[1,2,3], B=[4,5,6]);
fromdata = @from i in df begin
           @where i.B > 3
           @select {i.A}
           @orderby i.A
           @collect DataFrame

However, when you put a comment # in front of @orderBy, it works. Is this intended - why? (is an ordered DataFrame no longer a DataFrame?) … or is it a bug?

// Edit: Creating an explicit DataFrame again makes it work:

fromData = DataFrame(@from ... @orderby ... end)

// Edit: Rewritten question so that a naive copy/paste of the code should show the error.

where are these macros coming from?

Query (I added the using in my question).

Odd, it works for me. (DataFrames v0.19.1, Query v0.12.0.)

julia-1.3> using DataFrames, Query

julia-1.3> df = DataFrame(A=[1,2,3], B=[4,5,6]);

julia-1.3> fromdata = @from i in df begin
                      @where i.B > 3
                      @select {i.A}
                      @orderby i.A
                      @collect DataFrame
3x1 query result

First suggestion - a restart. I see many world age errors when I make mistakes in Query… :slight_smile:

I’m not sure, but is this alternative syntax equivalent?

df |> @filter(_.B > 3) |> @select(:A) |> @orderby(_.A) |> collect |> DataFrame

Thanks - I went down some other track (using sort!) … maybe it’s a problem with versions - I was using 1.1 (and am now on 1.2), you tried it in 1.3. I also did not check which package version I use(d) …

I just tried your code in 1.2, and it works.

Yeah, I also can’t replicate that error.

… when commenting in the @orderby? I get it “reliably” (in my Julia 1.1.1 installation - I have not yet upgraded … //edit: but let me upgrade - maybe I’m happy then!) - see the image below. More readably the output for the first two println()s is:

julia> println(typeof(fromdata))
QueryOperators.EnumerableMap{NamedTuple{(:A,),Tuple{Int64}},QueryOperators.EnumerableFilter{NamedTuple{(:A, :B),Tuple{Int64,Int64}},QueryOperators.EnumerableIterable{NamedTuple{(:A, :B),Tuple{Int64,Int64}},Tables.DataValueRowIterator{NamedTuple{(:A, :B),Tuple{Int64,Int64}},Tables.RowIterator{NamedTuple{(:A, :B),Tuple{Array{Int64,1},Array{Int64,1}}}}}},getfield(Main, Symbol("##2384#2386"))},getfield(Main, Symbol("##2385#2387"))}

julia> println(nrow(fromdata))
ERROR: MethodError: no method matching nrow(::QueryOperators.EnumerableMap{NamedTuple{(:A,),Tuple{Int64}},QueryOperators.EnumerableFilter{NamedTuple{(:A, :B),Tuple{Int64,Int64}},QueryOperators.EnumerableIterable{NamedTuple{(:A, :B),Tuple{Int64,Int64}},Tables.DataValueRowIterator{NamedTuple{(:A, :B),Tuple{Int64,Int64}},Tables.RowIterator{NamedTuple{(:A, :B),Tuple{Array{Int64,1},Array{Int64,1}}}}}},getfield(Main, Symbol("##2384#2386"))},getfield(Main, Symbol("##2385#2387"))})
Closest candidates are:
  nrow(::DataFrame) at C:\Users\h.mueller\.julia\packages\DataFrames\VrZOl\src\dataframe\dataframe.jl:278
  nrow(::SubDataFrame) at C:\Users\h.mueller\.julia\packages\DataFrames\VrZOl\src\subdataframe\subdataframe.jl:114
 [1] top-level scope at none:0


No - also does not work with 1.2.0 (DataFrames is 0.19.2, Query is 0.12.1).

(Edit: I have now rewritten the original question so that the code shown shows the error - just to make sure that people who copy it without reading the earlier instruction to remove the # will “hopefully” get the error).