|
49 | 49 | closure_val = 1 |
50 | 50 | @test DataFrame(df |> @mutate(foo = closure_val)) == DataFrame(foo=[1,1,1], bar=[3.,2.,1.], bat=["a","b","c"]) |
51 | 51 | end |
| 52 | + |
| 53 | +@testset "@dropna" begin |
| 54 | + |
| 55 | + df = DataFrame(a=[1,missing,3], b=[1.,2.,3.]) |
| 56 | + |
| 57 | + @test df |> @dropna() |> collect == [(a=1,b=1.), (a=3, b=3.)] |
| 58 | + @test df |> @filter(!any(isna, _)) |> @dropna() |> collect == [(a=1,b=1.), (a=3, b=3.)] |
| 59 | + @test df |> @select(:b) |> @dropna() |> collect == [(b=1.,),(b=2.,),(b=3.,)] |
| 60 | + |
| 61 | + @test df |> @dropna(:a) |> collect == [(a=1,b=1.), (a=3, b=3.)] |
| 62 | + @test df |> @dropna(:b) |> collect == [(a=DataValue(1),b=1.), (a=DataValue{Int}(),b=2.),(a=DataValue(3), b=3.)] |
| 63 | + @test df |> @dropna(:a, :b) |> collect == [(a=1,b=1.), (a=3, b=3.)] |
| 64 | +end |
| 65 | + |
| 66 | +@testset "@replacena" begin |
| 67 | + |
| 68 | + df = DataFrame(a=[1,missing,3], b=[1.,2.,3.]) |
| 69 | + |
| 70 | + @test df |> @replacena(2) |> collect == [(a=1,b=1.), (a=2, b=2.), (a=3, b=3.)] |
| 71 | + @test df |> @dropna() |> @replacena(2) |> collect == [(a=1,b=1.), (a=3, b=3.)] |
| 72 | + @test df |> @select(:b) |> @replacena(2) |> collect == [(b=1.,),(b=2.,),(b=3.,)] |
| 73 | + |
| 74 | + @test df |> @replacena(:a=>2) |> collect == [(a=1,b=1.), (a=2, b=2.), (a=3, b=3.)] |
| 75 | + @test df |> @replacena(:b=>2) |> collect == [(a=DataValue(1),b=1.), (a=DataValue{Int}(),b=2.),(a=DataValue(3), b=3.)] |
| 76 | + @test df |> @replacena(:a=>2, :b=>8) |> collect == [(a=1,b=1.), (a=2, b=2.), (a=3, b=3.)] |
| 77 | +end |
| 78 | + |
| 79 | +@testset "@dissallowna" begin |
| 80 | + |
| 81 | + df = DataFrame(a=[1,missing,3], b=[1.,2.,3.]) |
| 82 | + |
| 83 | + @test_throws DataValueException df |> @dissallowna() |> collect |
| 84 | + @test df |> @filter(!any(isna, _)) |> @dissallowna() |> collect == [(a=1,b=1.), (a=3, b=3.)] |
| 85 | + @test_throws DataValueException df |> @dissallowna(:a) |> collect |
| 86 | + @test df |> @dissallowna(:b) |> collect == [(a=DataValue(1),b=1.), (a=DataValue{Int}(),b=2.),(a=DataValue(3), b=3.)] |
| 87 | +end |
0 commit comments