|
9 | 9 |
|
10 | 10 | T = Map(1 => sin)
|
11 | 11 | n, c = apply(T, t)
|
12 |
| - @test Tables.schema(n).names == (:a, :b, :c, :d, :a_sin) |
13 |
| - @test n.a_sin == sin.(t.a) |
| 12 | + @test Tables.schema(n).names == (:a, :b, :c, :d, :sin_a) |
| 13 | + @test n.sin_a == sin.(t.a) |
14 | 14 |
|
15 | 15 | T = Map(:b => cos)
|
16 | 16 | n, c = apply(T, t)
|
17 |
| - @test Tables.schema(n).names == (:a, :b, :c, :d, :b_cos) |
18 |
| - @test n.b_cos == cos.(t.b) |
| 17 | + @test Tables.schema(n).names == (:a, :b, :c, :d, :cos_b) |
| 18 | + @test n.cos_b == cos.(t.b) |
19 | 19 |
|
20 | 20 | T = Map("c" => tan)
|
21 | 21 | n, c = apply(T, t)
|
22 |
| - @test Tables.schema(n).names == (:a, :b, :c, :d, :c_tan) |
23 |
| - @test n.c_tan == tan.(t.c) |
| 22 | + @test Tables.schema(n).names == (:a, :b, :c, :d, :tan_c) |
| 23 | + @test n.tan_c == tan.(t.c) |
24 | 24 |
|
25 | 25 | T = Map(:a => sin => :a)
|
26 | 26 | n, c = apply(T, t)
|
|
44 | 44 |
|
45 | 45 | T = Map(["c", "a"] => ((c, a) -> 3c / a) => :op1, "c" => tan)
|
46 | 46 | n, c = apply(T, t)
|
47 |
| - @test Tables.schema(n).names == (:a, :b, :c, :d, :op1, :c_tan) |
| 47 | + @test Tables.schema(n).names == (:a, :b, :c, :d, :op1, :tan_c) |
48 | 48 | @test n.op1 == @. 3 * t.c / t.a
|
49 |
| - @test n.c_tan == tan.(t.c) |
| 49 | + @test n.tan_c == tan.(t.c) |
50 | 50 |
|
51 | 51 | T = Map(r"[abc]" => ((a, b, c) -> a^2 - 2b + c) => "op1")
|
52 | 52 | n, c = apply(T, t)
|
53 | 53 | @test Tables.schema(n).names == (:a, :b, :c, :d, :op1)
|
54 | 54 | @test n.op1 == @. t.a^2 - 2 * t.b + t.c
|
55 | 55 |
|
56 |
| - # throws |
| 56 | + # generated names |
| 57 | + # normal function |
| 58 | + T = Map([:c, :d] => hypot) |
| 59 | + n, c = apply(T, t) |
| 60 | + @test Tables.schema(n).names == (:a, :b, :c, :d, :hypot_c_d) |
| 61 | + @test n.hypot_c_d == hypot.(t.c, t.d) |
| 62 | + |
| 63 | + # anonymous function |
| 64 | + f = a -> a^2 + 3 |
| 65 | + fname = replace(string(f), "#" => "f") |
| 66 | + colname = Symbol(fname, :_a) |
| 67 | + T = Map(:a => f) |
| 68 | + n, c = apply(T, t) |
| 69 | + @test Tables.schema(n).names == (:a, :b, :c, :d, colname) |
| 70 | + @test Tables.getcolumn(n, colname) == f.(t.a) |
| 71 | + |
| 72 | + # composed function |
| 73 | + f = sin ∘ cos |
| 74 | + T = Map(:b => f) |
| 75 | + n, c = apply(T, t) |
| 76 | + @test Tables.schema(n).names == (:a, :b, :c, :d, :sin_cos_b) |
| 77 | + @test n.sin_cos_b == f.(t.b) |
| 78 | + |
| 79 | + f = sin ∘ cos ∘ tan |
| 80 | + T = Map(:c => sin ∘ cos ∘ tan) |
| 81 | + n, c = apply(T, t) |
| 82 | + @test Tables.schema(n).names == (:a, :b, :c, :d, :sin_cos_tan_c) |
| 83 | + @test n.sin_cos_tan_c == f.(t.c) |
| 84 | + |
| 85 | + # Base.Fix1 |
| 86 | + f = Base.Fix1(hypot, 2) |
| 87 | + T = Map(:d => f) |
| 88 | + n, c = apply(T, t) |
| 89 | + @test Tables.schema(n).names == (:a, :b, :c, :d, :fix1_hypot_d) |
| 90 | + @test n.fix1_hypot_d == f.(t.d) |
| 91 | + |
| 92 | + # Base.Fix2 |
| 93 | + f = Base.Fix2(hypot, 2) |
| 94 | + T = Map(:a => f) |
| 95 | + n, c = apply(T, t) |
| 96 | + @test Tables.schema(n).names == (:a, :b, :c, :d, :fix2_hypot_a) |
| 97 | + @test n.fix2_hypot_a == f.(t.a) |
| 98 | + |
| 99 | + # error: cannot create Map transform without arguments |
57 | 100 | @test_throws ArgumentError Map()
|
58 | 101 | end
|
0 commit comments