Query.@mutate weirdness (bug?)

As I was trying to figure out another question, I found something that might be a bug (or perhaps a documentation bug) in Query.jl. According to the docs:

The @mutate command has the form source |> @mutate(args...). …
All args... are executed in order, and the result set of the previous mutation is the source of each current mutation.

However, in the following example, the old values of a seem to be used.

julia> DataFrame(a=[1,2], b=[0, 3]) |> 
            @mutate(a=_.a/2, b = _.a + _.b)
2x2 query result
a   β”‚ b
────┼──
0.5 β”‚ 1
1.0 β”‚ 5

This is not well formulated in the docs: individual args mutations don’t interdepend. If you want the computation of b to pickup _.a/2, you need to put it into a second @mutate statement.

I created https://github.com/queryverse/Query.jl/pull/316 deleting that sentence. If there is a better solution here, feel free to do that instead.

1 Like