|
| 1 | +@testset "DropNaN" begin |
| 2 | + @test !isrevertible(DropNaN()) |
| 3 | + |
| 4 | + a = [1.8, 0.5, 1.2, 3.7, 5.0, NaN] |
| 5 | + b = [6.0f0, 5.4f0, 5.4f0, NaN32, 5.5f0, 2.6f0] |
| 6 | + c = [4.9, 5.1, NaN, 5.1, 8.6, 4.4] * u"m" |
| 7 | + d = [NaN32, 1.0f0, 8.8f0, 0.1f0, 1.5f0, 9.5f0] * u"m" |
| 8 | + e = ["yes", "no", "no", "yes", "yes", "no"] |
| 9 | + t = Table(; a, b, c, d, e) |
| 10 | + |
| 11 | + T = DropNaN() |
| 12 | + n, c = apply(T, t) |
| 13 | + @test n.a == [0.5, 5.0] |
| 14 | + @test n.b == [5.4f0, 5.5f0] |
| 15 | + @test n.c == [5.1, 8.6] * u"m" |
| 16 | + @test n.d == [1.0f0, 1.5f0] * u"m" |
| 17 | + @test n.e == ["no", "yes"] |
| 18 | + |
| 19 | + # args... |
| 20 | + # integers |
| 21 | + T = DropNaN(1, 3) |
| 22 | + n, c = apply(T, t) |
| 23 | + @test isequal(n.a, [1.8, 0.5, 3.7, 5.0]) |
| 24 | + @test isequal(n.b, [6.0f0, 5.4f0, NaN32, 5.5f0]) |
| 25 | + @test isequal(n.c, [4.9, 5.1, 5.1, 8.6] * u"m") |
| 26 | + @test isequal(n.d, [NaN32, 1.0f0, 0.1f0, 1.5f0] * u"m") |
| 27 | + @test isequal(n.e, ["yes", "no", "yes", "yes"]) |
| 28 | + |
| 29 | + # symbols |
| 30 | + T = DropNaN(:a, :c) |
| 31 | + n, c = apply(T, t) |
| 32 | + @test isequal(n.a, [1.8, 0.5, 3.7, 5.0]) |
| 33 | + @test isequal(n.b, [6.0f0, 5.4f0, NaN32, 5.5f0]) |
| 34 | + @test isequal(n.c, [4.9, 5.1, 5.1, 8.6] * u"m") |
| 35 | + @test isequal(n.d, [NaN32, 1.0f0, 0.1f0, 1.5f0] * u"m") |
| 36 | + @test isequal(n.e, ["yes", "no", "yes", "yes"]) |
| 37 | + |
| 38 | + # strings |
| 39 | + T = DropNaN("a", "c") |
| 40 | + n, c = apply(T, t) |
| 41 | + @test isequal(n.a, [1.8, 0.5, 3.7, 5.0]) |
| 42 | + @test isequal(n.b, [6.0f0, 5.4f0, NaN32, 5.5f0]) |
| 43 | + @test isequal(n.c, [4.9, 5.1, 5.1, 8.6] * u"m") |
| 44 | + @test isequal(n.d, [NaN32, 1.0f0, 0.1f0, 1.5f0] * u"m") |
| 45 | + @test isequal(n.e, ["yes", "no", "yes", "yes"]) |
| 46 | + |
| 47 | + # vector |
| 48 | + # integers |
| 49 | + T = DropNaN([2, 4]) |
| 50 | + n, c = apply(T, t) |
| 51 | + @test isequal(n.a, [0.5, 1.2, 5.0, NaN]) |
| 52 | + @test isequal(n.b, [5.4f0, 5.4f0, 5.5f0, 2.6f0]) |
| 53 | + @test isequal(n.c, [5.1, NaN, 8.6, 4.4] * u"m") |
| 54 | + @test isequal(n.d, [1.0f0, 8.8f0, 1.5f0, 9.5f0] * u"m") |
| 55 | + @test isequal(n.e, ["no", "no", "yes", "no"]) |
| 56 | + |
| 57 | + # symbols |
| 58 | + T = DropNaN([:b, :d]) |
| 59 | + n, c = apply(T, t) |
| 60 | + @test isequal(n.a, [0.5, 1.2, 5.0, NaN]) |
| 61 | + @test isequal(n.b, [5.4f0, 5.4f0, 5.5f0, 2.6f0]) |
| 62 | + @test isequal(n.c, [5.1, NaN, 8.6, 4.4] * u"m") |
| 63 | + @test isequal(n.d, [1.0f0, 8.8f0, 1.5f0, 9.5f0] * u"m") |
| 64 | + @test isequal(n.e, ["no", "no", "yes", "no"]) |
| 65 | + |
| 66 | + # strings |
| 67 | + T = DropNaN(["b", "d"]) |
| 68 | + n, c = apply(T, t) |
| 69 | + @test isequal(n.a, [0.5, 1.2, 5.0, NaN]) |
| 70 | + @test isequal(n.b, [5.4f0, 5.4f0, 5.5f0, 2.6f0]) |
| 71 | + @test isequal(n.c, [5.1, NaN, 8.6, 4.4] * u"m") |
| 72 | + @test isequal(n.d, [1.0f0, 8.8f0, 1.5f0, 9.5f0] * u"m") |
| 73 | + @test isequal(n.e, ["no", "no", "yes", "no"]) |
| 74 | + |
| 75 | + # tuple |
| 76 | + # integers |
| 77 | + T = DropNaN((1, 2, 3)) |
| 78 | + n, c = apply(T, t) |
| 79 | + @test isequal(n.a, [1.8, 0.5, 5.0]) |
| 80 | + @test isequal(n.b, [6.0f0, 5.4f0, 5.5f0]) |
| 81 | + @test isequal(n.c, [4.9, 5.1, 8.6] * u"m") |
| 82 | + @test isequal(n.d, [NaN32, 1.0f0, 1.5f0] * u"m") |
| 83 | + @test isequal(n.e, ["yes", "no", "yes"]) |
| 84 | + |
| 85 | + # symbols |
| 86 | + T = DropNaN((:a, :b, :c)) |
| 87 | + n, c = apply(T, t) |
| 88 | + @test isequal(n.a, [1.8, 0.5, 5.0]) |
| 89 | + @test isequal(n.b, [6.0f0, 5.4f0, 5.5f0]) |
| 90 | + @test isequal(n.c, [4.9, 5.1, 8.6] * u"m") |
| 91 | + @test isequal(n.d, [NaN32, 1.0f0, 1.5f0] * u"m") |
| 92 | + @test isequal(n.e, ["yes", "no", "yes"]) |
| 93 | + |
| 94 | + # strings |
| 95 | + T = DropNaN(("a", "b", "c")) |
| 96 | + n, c = apply(T, t) |
| 97 | + @test isequal(n.a, [1.8, 0.5, 5.0]) |
| 98 | + @test isequal(n.b, [6.0f0, 5.4f0, 5.5f0]) |
| 99 | + @test isequal(n.c, [4.9, 5.1, 8.6] * u"m") |
| 100 | + @test isequal(n.d, [NaN32, 1.0f0, 1.5f0] * u"m") |
| 101 | + @test isequal(n.e, ["yes", "no", "yes"]) |
| 102 | + |
| 103 | + # regex |
| 104 | + T = DropNaN(r"[bcd]") |
| 105 | + n, c = apply(T, t) |
| 106 | + @test isequal(n.a, [0.5, 5.0, NaN]) |
| 107 | + @test isequal(n.b, [5.4f0, 5.5f0, 2.6f0]) |
| 108 | + @test isequal(n.c, [5.1, 8.6, 4.4] * u"m") |
| 109 | + @test isequal(n.d, [1.0f0, 1.5f0, 9.5f0] * u"m") |
| 110 | + @test isequal(n.e, ["no", "yes", "no"]) |
| 111 | +end |
0 commit comments