# Query.@mutate weirdness (bug?)

**URL:** <https://discourse.julialang.org/t/query-mutate-weirdness-bug/44642>\
**Category:** Data\
**Created:** [August 9, 2020, 9:21pm UTC](https://discourse.julialang.org/t/query-mutate-weirdness-bug/44642 "2020-08-09T21:21:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ilyagr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ilyagr/32/17022_2.png) [@ilyagr](https://discourse.julialang.org/u/ilyagr)\
**Post date:** [August 9, 2020, 9:21pm UTC](https://discourse.julialang.org/t/query-mutate-weirdness-bug/44642/1 "2020-08-09T21:21:04Z")

</div>

As I was trying to figure out [another question](https://discourse.julialang.org/t/does-query-jl-have-a-good-way-to-implement-mutations-that-depend-on-each-other/44643), I found something that might be a bug (or perhaps a documentation bug) in Query.jl. According to [the docs](https://www.queryverse.org/Query.jl/v1.0/standalonequerycommands/#The-@mutate-command-1):

> 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
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

```

---

<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:** [August 10, 2020, 9:34pm UTC](https://discourse.julialang.org/t/query-mutate-weirdness-bug/44642/2 "2020-08-10T21:34:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ilyagr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ilyagr/32/17022_2.png) [@ilyagr](https://discourse.julialang.org/u/ilyagr)\
**Post date:** [August 12, 2020, 9:49pm UTC](https://discourse.julialang.org/t/query-mutate-weirdness-bug/44642/3 "2020-08-12T21:49:35Z")

</div>

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