Queryverse @map question

I have

describe(gewig)

Summary Stats:
Mean:           2979.413793
Minimum:        1613.000000
1st Quartile:   2226.500000
Median:         2822.500000
3rd Quartile:   3618.250000
Maximum:        5140.000000
Length:         406
Type:           Int64

According to a Queryverse tutorial I can do

 gewig |> @map({foo=_, bar=_^2}) 

which works as expected.

But when I do this:

m = 2979.413793
sa = std(gewig, mean = m)
gewig |> @map({foo=_, bar=(_-m)/sa})

I get an error which I do not understand:

type UnionAll has no field parameters

What is the correct way to do this?

Are you running this in the REPL? It looks like Query cannot be certain of the types of the values m and sa because they are non-constant globals, and I think Query relies on type inference to know what the final column types should be. The first example is okay because the 2 in ^2 is hardcoded and the compiler knows its type can’t change.

I understand there are plans to remove this reliance on type inference in the future. But for now, if you wrap all the code in a function or declare the variables as constant beforehand (e.g. const m = 2979.413793) then it should work.

1 Like

Thanks for the clarification.
Defining constants helped in this case (using REPL).

Yep, that is correct. The version that runs on 0.7 will drop the reliance on type inference, I’m almost done with it.

5 Likes