diff --git a/test/broadcasting.jl b/test/broadcasting.jl index 420c7d05e..1491c7099 100644 --- a/test/broadcasting.jl +++ b/test/broadcasting.jl @@ -1043,10 +1043,18 @@ end @testset "scalar on assignment side" begin df = DataFrame(rand(2, 3), :auto) - @test_throws MethodError df[1, 1] .= df[1, 1] .- df[1, 1] + if VERSION >= v"1.14.0-DEV" + @test_throws ArgumentError df[1, 1] .= df[1, 1] .- df[1, 1] + else + @test_throws MethodError df[1, 1] .= df[1, 1] .- df[1, 1] + end df[1, 1:1] .= df[1, 1] .- df[1, 1] @test df[1, 1] == 0 - @test_throws MethodError df[1, 2] .-= df[1, 2] + if VERSION >= v"1.14.0-DEV" + @test_throws ArgumentError df[1, 2] .-= df[1, 2] + else + @test_throws MethodError df[1, 2] .-= df[1, 2] + end df[1:1, 2] .-= df[1, 2] @test df[1, 2] == 0 end @@ -1288,29 +1296,55 @@ end end @testset "additional checks of post-! broadcasting rules" begin - df = copy(refdf) - v1 = df[!, 1] - @test_throws MethodError df[CartesianIndex(1, 1)] .= 1 - @test_throws MethodError df[CartesianIndex(1, 1)] .= "d" - @test_throws DimensionMismatch df[CartesianIndex(1, 1)] .= [1, 2] + if VERSION >= v"1.14.0-DEV" + df = copy(refdf) + v1 = df[!, 1] + @test_throws ArgumentError df[CartesianIndex(1, 1)] .= 1 + @test_throws ArgumentError df[CartesianIndex(1, 1)] .= "d" + @test_throws ArgumentError df[CartesianIndex(1, 1)] .= [1, 2] - df = copy(refdf) - v1 = df[!, 1] - @test_throws MethodError df[1, 1] .= 1 - @test_throws MethodError df[1, 1] .= "d" - @test_throws DimensionMismatch df[1, 1] .= [1, 2] + df = copy(refdf) + v1 = df[!, 1] + @test_throws ArgumentError df[1, 1] .= 1 + @test_throws ArgumentError df[1, 1] .= "d" + @test_throws ArgumentError df[1, 1] .= [1, 2] - df = copy(refdf) - v1 = df[!, 1] - @test_throws MethodError df[1, :x1] .= 1 - @test_throws MethodError df[1, :x1] .= "d" - @test_throws DimensionMismatch df[1, :x1] .= [1, 2] + df = copy(refdf) + v1 = df[!, 1] + @test_throws ArgumentError df[1, :x1] .= 1 + @test_throws ArgumentError df[1, :x1] .= "d" + @test_throws ArgumentError df[1, :x1] .= [1, 2] - df = copy(refdf) - v1 = df[!, 1] - @test_throws MethodError df[1, "x1"] .= 1 - @test_throws MethodError df[1, "x1"] .= "d" - @test_throws DimensionMismatch df[1, "x1"] .= [1, 2] + df = copy(refdf) + v1 = df[!, 1] + @test_throws ArgumentError df[1, "x1"] .= 1 + @test_throws ArgumentError df[1, "x1"] .= "d" + @test_throws ArgumentError df[1, "x1"] .= [1, 2] + else + df = copy(refdf) + v1 = df[!, 1] + @test_throws MethodError df[CartesianIndex(1, 1)] .= 1 + @test_throws MethodError df[CartesianIndex(1, 1)] .= "d" + @test_throws DimensionMismatch df[CartesianIndex(1, 1)] .= [1, 2] + + df = copy(refdf) + v1 = df[!, 1] + @test_throws Exception df[1, 1] .= 1 + @test_throws Exception df[1, 1] .= "d" + @test_throws Exception df[1, 1] .= [1, 2] + + df = copy(refdf) + v1 = df[!, 1] + @test_throws Exception df[1, :x1] .= 1 + @test_throws Exception df[1, :x1] .= "d" + @test_throws Exception df[1, :x1] .= [1, 2] + + df = copy(refdf) + v1 = df[!, 1] + @test_throws Exception df[1, "x1"] .= 1 + @test_throws Exception df[1, "x1"] .= "d" + @test_throws Exception df[1, "x1"] .= [1, 2] + end df = copy(refdf) v1 = df[!, 1] @@ -1483,23 +1517,43 @@ end df.newcol .= 'd' @test df == [refdf DataFrame(newcol=fill('d', 3))] - df = view(copy(refdf), :, :) - v1 = df[!, 1] - @test_throws MethodError df[CartesianIndex(1, 1)] .= 1 - @test_throws MethodError df[CartesianIndex(1, 1)] .= "d" - @test_throws DimensionMismatch df[CartesianIndex(1, 1)] .= [1, 2] - - df = view(copy(refdf), :, :) - v1 = df[!, 1] - @test_throws MethodError df[1, 1] .= 1 - @test_throws MethodError df[1, 1] .= "d" - @test_throws DimensionMismatch df[1, 1] .= [1, 2] - - df = view(copy(refdf), :, :) - v1 = df[!, 1] - @test_throws MethodError df[1, :x1] .= 1 - @test_throws MethodError df[1, :x1] .= "d" - @test_throws DimensionMismatch df[1, :x1] .= [1, 2] + if VERSION >= v"1.14.0-DEV" + df = view(copy(refdf), :, :) + v1 = df[!, 1] + @test_throws ArgumentError df[CartesianIndex(1, 1)] .= 1 + @test_throws ArgumentError df[CartesianIndex(1, 1)] .= "d" + @test_throws ArgumentError df[CartesianIndex(1, 1)] .= [1, 2] + + df = view(copy(refdf), :, :) + v1 = df[!, 1] + @test_throws ArgumentError df[1, 1] .= 1 + @test_throws ArgumentError df[1, 1] .= "d" + @test_throws ArgumentError df[1, 1] .= [1, 2] + + df = view(copy(refdf), :, :) + v1 = df[!, 1] + @test_throws ArgumentError df[1, :x1] .= 1 + @test_throws ArgumentError df[1, :x1] .= "d" + @test_throws ArgumentError df[1, :x1] .= [1, 2] + else + df = view(copy(refdf), :, :) + v1 = df[!, 1] + @test_throws MethodError df[CartesianIndex(1, 1)] .= 1 + @test_throws MethodError df[CartesianIndex(1, 1)] .= "d" + @test_throws DimensionMismatch df[CartesianIndex(1, 1)] .= [1, 2] + + df = view(copy(refdf), :, :) + v1 = df[!, 1] + @test_throws MethodError df[1, 1] .= 1 + @test_throws MethodError df[1, 1] .= "d" + @test_throws DimensionMismatch df[1, 1] .= [1, 2] + + df = view(copy(refdf), :, :) + v1 = df[!, 1] + @test_throws MethodError df[1, :x1] .= 1 + @test_throws MethodError df[1, :x1] .= "d" + @test_throws DimensionMismatch df[1, :x1] .= [1, 2] + end df = view(copy(refdf), :, :) v1 = df[!, 1] @@ -1676,9 +1730,15 @@ end @testset "add new correct rules for df[row, col] .= v broadcasting" begin for v in [:a, "a"] df = DataFrame(a=1) - @test_throws MethodError df[1, 1] .= 10 - @test_throws MethodError df[1, v] .= 10 - @test_throws MethodError df[CartesianIndex(1, 1)] .= 10 + if VERSION >= v"1.14.0-DEV" + @test_throws ArgumentError df[1, 1] .= 10 + @test_throws ArgumentError df[1, v] .= 10 + @test_throws ArgumentError df[CartesianIndex(1, 1)] .= 10 + else + @test_throws MethodError df[1, 1] .= 10 + @test_throws MethodError df[1, v] .= 10 + @test_throws MethodError df[CartesianIndex(1, 1)] .= 10 + end df = DataFrame(a=[[1, 2, 3]]) df[1, 1] .= 10 @test df == DataFrame(a=[[10, 10, 10]]) diff --git a/test/indexing.jl b/test/indexing.jl index f4b01e2de..2bcc257ef 100644 --- a/test/indexing.jl +++ b/test/indexing.jl @@ -1727,7 +1727,12 @@ end dfr[["a", "b"]] = (a=1000, b=2000) @test copy(dfr) == (b=2000, a=1000) - @test_throws MethodError dfr["a"] .= 100 + if VERSION >= v"1.14.0-DEV" + @test_throws ArgumentError dfr["a"] .= 100 + else + @test_throws MethodError dfr["a"] .= 100 + end + dfr[["a", "b"]] .= 50 @test copy(dfr) == (b=50, a=50) end