|
| 1 | +@testset "Indicator" begin |
| 2 | + a = [5.8, 6.4, 6.4, 9.8, 7.6, 8.2, 4.5, 2.5, 1.7, 2.3] |
| 3 | + b = [8.4, 1.4, 7.2, 1.8, 9.4, 1.0, 2.0, 5.2, 9.4, 6.2] |
| 4 | + c = [4.1, 5.6, 7.1, 9.1, 5.9, 9.5, 5.7, 9.0, 6.6, 9.9] |
| 5 | + d = [7.5, 2.2, 1.6, 2.8, 1.2, 1.5, 3.7, 2.0, 8.3, 8.2] |
| 6 | + t = Table(; a, b, c, d) |
| 7 | + |
| 8 | + T = Indicator(:a, k=1, scale=:quantile) |
| 9 | + n, c = apply(T, t) |
| 10 | + @test Tables.columnnames(n) == (:a_1, :b, :c, :d) |
| 11 | + @test n.a_1 == Bool[1, 1, 1, 1, 1, 1, 1, 1, 1, 1] |
| 12 | + @test n.a_1 isa BitVector |
| 13 | + tₒ = revert(T, n, c) |
| 14 | + @test t == tₒ |
| 15 | + |
| 16 | + T = Indicator(:b, k=2, scale=:quantile) |
| 17 | + n, c = apply(T, t) |
| 18 | + @test Tables.columnnames(n) == (:a, :b_1, :b_2, :c, :d) |
| 19 | + @test n.b_1 == Bool[0, 1, 0, 1, 0, 1, 1, 1, 0, 0] |
| 20 | + @test n.b_2 == Bool[1, 1, 1, 1, 1, 1, 1, 1, 1, 1] |
| 21 | + @test n.b_1 isa BitVector |
| 22 | + @test n.b_2 isa BitVector |
| 23 | + tₒ = revert(T, n, c) |
| 24 | + @test t == tₒ |
| 25 | + |
| 26 | + T = Indicator(:c, k=3, scale=:quantile, categ=true) |
| 27 | + n, c = apply(T, t) |
| 28 | + @test Tables.columnnames(n) == (:a, :b, :c_1, :c_2, :c_3, :d) |
| 29 | + @test n.c_1 == categorical(Bool[1, 1, 0, 0, 1, 0, 1, 0, 0, 0]) |
| 30 | + @test n.c_2 == categorical(Bool[1, 1, 1, 0, 1, 0, 1, 0, 1, 0]) |
| 31 | + @test n.c_3 == categorical(Bool[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) |
| 32 | + @test n.c_1 isa CategoricalVector{Bool} |
| 33 | + @test n.c_2 isa CategoricalVector{Bool} |
| 34 | + @test n.c_3 isa CategoricalVector{Bool} |
| 35 | + tₒ = revert(T, n, c) |
| 36 | + @test t == tₒ |
| 37 | + |
| 38 | + T = Indicator(:d, k=4, scale=:quantile, categ=true) |
| 39 | + n, c = apply(T, t) |
| 40 | + @test Tables.columnnames(n) == (:a, :b, :c, :d_1, :d_2, :d_3, :d_4) |
| 41 | + @test n.d_1 == categorical(Bool[0, 0, 1, 0, 1, 1, 0, 0, 0, 0]) |
| 42 | + @test n.d_2 == categorical(Bool[0, 1, 1, 0, 1, 1, 0, 1, 0, 0]) |
| 43 | + @test n.d_3 == categorical(Bool[0, 1, 1, 1, 1, 1, 1, 1, 0, 0]) |
| 44 | + @test n.d_4 == categorical(Bool[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) |
| 45 | + @test n.d_1 isa CategoricalVector{Bool} |
| 46 | + @test n.d_2 isa CategoricalVector{Bool} |
| 47 | + @test n.d_3 isa CategoricalVector{Bool} |
| 48 | + @test n.d_4 isa CategoricalVector{Bool} |
| 49 | + tₒ = revert(T, n, c) |
| 50 | + @test t == tₒ |
| 51 | + |
| 52 | + T = Indicator(:a, k=1, scale=:linear) |
| 53 | + n, c = apply(T, t) |
| 54 | + @test Tables.columnnames(n) == (:a_1, :b, :c, :d) |
| 55 | + @test n.a_1 == Bool[1, 1, 1, 1, 1, 1, 1, 1, 1, 1] |
| 56 | + @test n.a_1 isa BitVector |
| 57 | + tₒ = revert(T, n, c) |
| 58 | + @test t == tₒ |
| 59 | + |
| 60 | + T = Indicator(:b, k=2, scale=:linear) |
| 61 | + n, c = apply(T, t) |
| 62 | + @test Tables.columnnames(n) == (:a, :b_1, :b_2, :c, :d) |
| 63 | + @test n.b_1 == Bool[0, 1, 0, 1, 0, 1, 1, 1, 0, 0] |
| 64 | + @test n.b_2 == Bool[1, 1, 1, 1, 1, 1, 1, 1, 1, 1] |
| 65 | + @test n.b_1 isa BitVector |
| 66 | + @test n.b_2 isa BitVector |
| 67 | + tₒ = revert(T, n, c) |
| 68 | + @test t == tₒ |
| 69 | + |
| 70 | + T = Indicator(:c, k=3, scale=:linear, categ=true) |
| 71 | + n, c = apply(T, t) |
| 72 | + @test Tables.columnnames(n) == (:a, :b, :c_1, :c_2, :c_3, :d) |
| 73 | + @test n.c_1 == categorical(Bool[1, 1, 0, 0, 1, 0, 1, 0, 0, 0]) |
| 74 | + @test n.c_2 == categorical(Bool[1, 1, 1, 0, 1, 0, 1, 0, 1, 0]) |
| 75 | + @test n.c_3 == categorical(Bool[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) |
| 76 | + @test n.c_1 isa CategoricalVector{Bool} |
| 77 | + @test n.c_2 isa CategoricalVector{Bool} |
| 78 | + @test n.c_3 isa CategoricalVector{Bool} |
| 79 | + tₒ = revert(T, n, c) |
| 80 | + @test t == tₒ |
| 81 | + |
| 82 | + T = Indicator(:d, k=4, scale=:linear, categ=true) |
| 83 | + n, c = apply(T, t) |
| 84 | + @test Tables.columnnames(n) == (:a, :b, :c, :d_1, :d_2, :d_3, :d_4) |
| 85 | + @test n.d_1 == categorical(Bool[0, 1, 1, 1, 1, 1, 0, 1, 0, 0]) |
| 86 | + @test n.d_2 == categorical(Bool[0, 1, 1, 1, 1, 1, 1, 1, 0, 0]) |
| 87 | + @test n.d_3 == categorical(Bool[0, 1, 1, 1, 1, 1, 1, 1, 0, 0]) |
| 88 | + @test n.d_4 == categorical(Bool[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) |
| 89 | + @test n.d_1 isa CategoricalVector{Bool} |
| 90 | + @test n.d_2 isa CategoricalVector{Bool} |
| 91 | + @test n.d_3 isa CategoricalVector{Bool} |
| 92 | + @test n.d_4 isa CategoricalVector{Bool} |
| 93 | + tₒ = revert(T, n, c) |
| 94 | + @test t == tₒ |
| 95 | + |
| 96 | + @test_throws ArgumentError Indicator(:a, k=0) |
| 97 | + @test_throws ArgumentError Indicator(:a, scale=:test) |
| 98 | +end |
0 commit comments