|
1 | 1 | @testset "OneHot" begin
|
2 |
| - a = categorical(Bool[0, 1, 1, 0, 1, 1]) |
3 |
| - b = categorical(["m", "f", "m", "m", "m", "f"]) |
4 |
| - c = categorical([3, 2, 2, 1, 1, 3]) |
5 |
| - t = Table(; a, b, c) |
| 2 | + a = Bool[0, 1, 1, 0, 1, 1] |
| 3 | + b = ["m", "f", "m", "m", "m", "f"] |
| 4 | + c = [3, 2, 2, 1, 1, 3] |
| 5 | + d = categorical(a) |
| 6 | + e = categorical(b) |
| 7 | + f = categorical(c) |
| 8 | + t = Table(; a, b, c, d, e, f) |
6 | 9 |
|
7 | 10 | T = OneHot(1; categ=true)
|
8 | 11 | n, c = apply(T, t)
|
9 |
| - @test Tables.columnnames(n) == (:a_false, :a_true, :b, :c) |
| 12 | + @test Tables.columnnames(n) == (:a_false, :a_true, :b, :c, :d, :e, :f) |
10 | 13 | @test n.a_false == categorical(Bool[1, 0, 0, 1, 0, 0])
|
11 | 14 | @test n.a_true == categorical(Bool[0, 1, 1, 0, 1, 1])
|
12 | 15 | @test n.a_false isa CategoricalVector{Bool}
|
13 | 16 | @test n.a_true isa CategoricalVector{Bool}
|
14 | 17 | tₒ = revert(T, n, c)
|
15 |
| - @test t == tₒ |
| 18 | + @test Tables.schema(tₒ) == Tables.schema(t) |
| 19 | + @test tₒ == t |
16 | 20 |
|
17 | 21 | T = OneHot(:b; categ=true)
|
18 | 22 | n, c = apply(T, t)
|
19 |
| - @test Tables.columnnames(n) == (:a, :b_f, :b_m, :c) |
| 23 | + @test Tables.columnnames(n) == (:a, :b_f, :b_m, :c, :d, :e, :f) |
20 | 24 | @test n.b_f == categorical(Bool[0, 1, 0, 0, 0, 1])
|
21 | 25 | @test n.b_m == categorical(Bool[1, 0, 1, 1, 1, 0])
|
22 | 26 | @test n.b_f isa CategoricalVector{Bool}
|
23 | 27 | @test n.b_m isa CategoricalVector{Bool}
|
24 | 28 | tₒ = revert(T, n, c)
|
25 |
| - @test t == tₒ |
| 29 | + @test Tables.schema(tₒ) == Tables.schema(t) |
| 30 | + @test tₒ == t |
26 | 31 |
|
27 | 32 | T = OneHot("c"; categ=true)
|
28 | 33 | n, c = apply(T, t)
|
29 |
| - @test Tables.columnnames(n) == (:a, :b, :c_1, :c_2, :c_3) |
| 34 | + @test Tables.columnnames(n) == (:a, :b, :c_1, :c_2, :c_3, :d, :e, :f) |
30 | 35 | @test n.c_1 == categorical(Bool[0, 0, 0, 1, 1, 0])
|
31 | 36 | @test n.c_2 == categorical(Bool[0, 1, 1, 0, 0, 0])
|
32 | 37 | @test n.c_3 == categorical(Bool[1, 0, 0, 0, 0, 1])
|
33 | 38 | @test n.c_1 isa CategoricalVector{Bool}
|
34 | 39 | @test n.c_2 isa CategoricalVector{Bool}
|
35 | 40 | @test n.c_3 isa CategoricalVector{Bool}
|
36 | 41 | tₒ = revert(T, n, c)
|
37 |
| - @test t == tₒ |
| 42 | + @test Tables.schema(tₒ) == Tables.schema(t) |
| 43 | + @test tₒ == t |
38 | 44 |
|
39 |
| - T = OneHot(1; categ=false) |
| 45 | + T = OneHot(4; categ=false) |
40 | 46 | n, c = apply(T, t)
|
41 |
| - @test Tables.columnnames(n) == (:a_false, :a_true, :b, :c) |
42 |
| - @test n.a_false == Bool[1, 0, 0, 1, 0, 0] |
43 |
| - @test n.a_true == Bool[0, 1, 1, 0, 1, 1] |
| 47 | + @test Tables.columnnames(n) == (:a, :b, :c, :d_false, :d_true, :e, :f) |
| 48 | + @test n.d_false == Bool[1, 0, 0, 1, 0, 0] |
| 49 | + @test n.d_true == Bool[0, 1, 1, 0, 1, 1] |
44 | 50 | tₒ = revert(T, n, c)
|
45 |
| - @test t == tₒ |
| 51 | + @test Tables.schema(tₒ) == Tables.schema(t) |
| 52 | + @test tₒ == t |
46 | 53 |
|
47 |
| - T = OneHot(:b; categ=false) |
| 54 | + T = OneHot(:e; categ=false) |
48 | 55 | n, c = apply(T, t)
|
49 |
| - @test Tables.columnnames(n) == (:a, :b_f, :b_m, :c) |
50 |
| - @test n.b_f == Bool[0, 1, 0, 0, 0, 1] |
51 |
| - @test n.b_m == Bool[1, 0, 1, 1, 1, 0] |
| 56 | + @test Tables.columnnames(n) == (:a, :b, :c, :d, :e_f, :e_m, :f) |
| 57 | + @test n.e_f == Bool[0, 1, 0, 0, 0, 1] |
| 58 | + @test n.e_m == Bool[1, 0, 1, 1, 1, 0] |
52 | 59 | tₒ = revert(T, n, c)
|
53 |
| - @test t == tₒ |
| 60 | + @test Tables.schema(tₒ) == Tables.schema(t) |
| 61 | + @test tₒ == t |
54 | 62 |
|
55 |
| - T = OneHot("c"; categ=false) |
| 63 | + T = OneHot("f"; categ=false) |
56 | 64 | n, c = apply(T, t)
|
57 |
| - @test Tables.columnnames(n) == (:a, :b, :c_1, :c_2, :c_3) |
58 |
| - @test n.c_1 == Bool[0, 0, 0, 1, 1, 0] |
59 |
| - @test n.c_2 == Bool[0, 1, 1, 0, 0, 0] |
60 |
| - @test n.c_3 == Bool[1, 0, 0, 0, 0, 1] |
| 65 | + @test Tables.columnnames(n) == (:a, :b, :c, :d, :e, :f_1, :f_2, :f_3) |
| 66 | + @test n.f_1 == Bool[0, 0, 0, 1, 1, 0] |
| 67 | + @test n.f_2 == Bool[0, 1, 1, 0, 0, 0] |
| 68 | + @test n.f_3 == Bool[1, 0, 0, 0, 0, 1] |
61 | 69 | tₒ = revert(T, n, c)
|
62 |
| - @test t == tₒ |
| 70 | + @test Tables.schema(tₒ) == Tables.schema(t) |
| 71 | + @test tₒ == t |
63 | 72 |
|
64 | 73 | # name formatting
|
65 | 74 | b = categorical(["m", "f", "m", "m", "m", "f"])
|
66 |
| - b_f = rand(10) |
67 |
| - b_m = rand(10) |
| 75 | + b_f = rand(6) |
| 76 | + b_m = rand(6) |
68 | 77 | t = Table(; b, b_f, b_m)
|
69 | 78 |
|
70 | 79 | T = OneHot(:b; categ=false)
|
|
76 | 85 | @test t == tₒ
|
77 | 86 |
|
78 | 87 | b = categorical(["m", "f", "m", "m", "m", "f"])
|
79 |
| - b_f = rand(10) |
80 |
| - b_m = rand(10) |
81 |
| - b_f_ = rand(10) |
82 |
| - b_m_ = rand(10) |
| 88 | + b_f = rand(6) |
| 89 | + b_m = rand(6) |
| 90 | + b_f_ = rand(6) |
| 91 | + b_m_ = rand(6) |
83 | 92 | t = Table(; b, b_f, b_m, b_f_, b_m_)
|
84 | 93 |
|
85 | 94 | T = OneHot(:b; categ=false)
|
|
91 | 100 | @test t == tₒ
|
92 | 101 |
|
93 | 102 | # throws
|
94 |
| - a = categorical(Bool[0, 1, 1, 0, 1, 1]) |
95 |
| - b = ["m", "f", "m", "m", "m", "f"] |
| 103 | + a = Bool[0, 1, 1, 0, 1, 1] |
| 104 | + b = rand(6) |
96 | 105 | t = Table(; a, b)
|
97 | 106 |
|
98 | 107 | # non categorical column
|
|
0 commit comments