925
925
DataFrame (x1= Char[], a= Int[])
926
926
end
927
927
@test_throws ArgumentError select (df, [] => (() -> [9 ]) => :a , :)
928
- @test_throws ArgumentError select (df, :, [] => (() -> [9 ]) => :a )
928
+ @test_throws DimensionMismatch select (df, :, [] => (() -> [9 ]) => :a )
929
929
@test transform (df, names (df) .=> (x -> 9 ) .=> names (df)) ==
930
930
repeat (DataFrame ([9 9 9 ], :auto ), nrow (df))
931
931
@test combine (df, names (df) .=> (x -> 9 ) .=> names (df)) ==
@@ -1011,15 +1011,15 @@ end
1011
1011
@test df2. x4_last isa CategoricalVector{Int}
1012
1012
end
1013
1013
1014
- @test_throws ArgumentError select (df, names (df) .=> first, [] => (() -> Int[]) => :x1 )
1014
+ @test_throws DimensionMismatch select (df, names (df) .=> first, [] => (() -> Int[]) => :x1 )
1015
1015
df2 = combine (df, names (df) .=> first, [] => (() -> Int[]) => :x1 )
1016
1016
@test size (df2) == (0 , 5 )
1017
1017
@test df2. x1_first isa Vector{Int}
1018
1018
@test df2. x2_first isa CategoricalVector{Int}
1019
1019
@test df2. x3_first isa Vector{Missing}
1020
1020
@test df2. x4_first isa Vector{Missing}
1021
1021
1022
- @test_throws ArgumentError select (df, names (df) .=> last, [] => (() -> Int[]) => :x1 )
1022
+ @test_throws DimensionMismatch select (df, names (df) .=> last, [] => (() -> Int[]) => :x1 )
1023
1023
df2 = combine (df, names (df) .=> last, [] => (() -> Int[]) => :x1 )
1024
1024
@test size (df2) == (0 , 5 )
1025
1025
@test df2. x1_last isa Vector{Int}
@@ -1273,8 +1273,8 @@ end
1273
1273
@test df2. y === df. y
1274
1274
@test transform (df, names (df) .=> first .=> names (df)) ==
1275
1275
DataFrame (x= fill (1 , 3 ), y= fill (4 , 3 ))
1276
- @test_throws ArgumentError transform (df, :x => x -> [first (x)], copycols= true )
1277
- @test_throws ArgumentError transform (df, :x => x -> [first (x)], copycols= false )
1276
+ @test_throws DimensionMismatch transform (df, :x => x -> [first (x)], copycols= true )
1277
+ @test_throws DimensionMismatch transform (df, :x => x -> [first (x)], copycols= false )
1278
1278
1279
1279
dfv = view (df, [2 , 1 ], [2 , 1 ])
1280
1280
@test select (dfv, :x => first) == DataFrame (x_first= fill (2 , 2 ))
@@ -1292,8 +1292,8 @@ end
1292
1292
@test_throws ArgumentError transform (dfv, :x => first, copycols= false )
1293
1293
@test transform (dfv, names (dfv) .=> first .=> names (dfv)) ==
1294
1294
DataFrame (y= fill (5 , 2 ), x= fill (2 , 2 ))
1295
- @test_throws ArgumentError transform (df, :x => x -> [first (x)], copycols= true )
1296
- @test_throws ArgumentError transform (df, :x => x -> [first (x)], copycols= false )
1295
+ @test_throws DimensionMismatch transform (df, :x => x -> [first (x)], copycols= true )
1296
+ @test_throws DimensionMismatch transform (df, :x => x -> [first (x)], copycols= false )
1297
1297
end
1298
1298
1299
1299
@testset " select! and transform! AbstractDataFrame" begin
@@ -1327,7 +1327,7 @@ end
1327
1327
@test df == DataFrame (x= fill (1 , 3 ), y= fill (4 , 3 ))
1328
1328
1329
1329
df = DataFrame (x= 1 : 3 , y= 4 : 6 )
1330
- @test_throws ArgumentError transform! (df, :x => x -> [1 ])
1330
+ @test_throws DimensionMismatch transform! (df, :x => x -> [1 ])
1331
1331
@test df == DataFrame (x= 1 : 3 , y= 4 : 6 )
1332
1332
1333
1333
dfv = view (df, [2 , 1 ], [2 , 1 ])
@@ -1387,7 +1387,7 @@ end
1387
1387
@test transform (sdf -> sdf. b, df) == [df DataFrame (x1= 3 : 4 )]
1388
1388
@test transform (sdf -> (b = 2 sdf. b,), df) == DataFrame (a= 1 : 2 , b= [6 , 8 ], c= 5 : 6 )
1389
1389
@test transform (sdf -> (b = 1 ,), df) == DataFrame (a= [1 , 2 ], b= [1 , 1 ], c= [5 , 6 ])
1390
- @test_throws ArgumentError transform (sdf -> (b = [1 ],), df)
1390
+ @test_throws DimensionMismatch transform (sdf -> (b = [1 ],), df)
1391
1391
@test transform (sdf -> (b = [1 , 5 ],), df) == DataFrame (a= [1 , 2 ], b= [1 , 5 ], c= [5 , 6 ])
1392
1392
@test transform (sdf -> 1 , df) == DataFrame (a= 1 : 2 , b= 3 : 4 , c= 5 : 6 , x1= 1 )
1393
1393
@test transform (sdf -> fill ([1 ]), df) == DataFrame (a= 1 : 2 , b= 3 : 4 , c= 5 : 6 , x1= [[1 ], [1 ]])
@@ -1397,8 +1397,8 @@ end
1397
1397
for ret in (DataFrame (), NamedTuple (), zeros (0 , 0 ), DataFrame (t= 1 )[1 , 1 : 0 ])
1398
1398
@test transform (sdf -> ret, df) == df
1399
1399
end
1400
- @test_throws ArgumentError transform (sdf -> DataFrame (a= 10 ), df)
1401
- @test_throws ArgumentError transform (sdf -> zeros (1 , 2 ), df)
1400
+ @test_throws DimensionMismatch transform (sdf -> DataFrame (a= 10 ), df)
1401
+ @test_throws DimensionMismatch transform (sdf -> zeros (1 , 2 ), df)
1402
1402
@test transform (sdf -> DataFrame (a= [10 , 11 ]), df) == DataFrame (a= [10 , 11 ], b= 3 : 4 , c= 5 : 6 )
1403
1403
@test transform (sdf -> [10 11 ; 12 13 ], df) == DataFrame (a= 1 : 2 , b= 3 : 4 , c= 5 : 6 , x1= [10 , 12 ], x2= [11 , 13 ])
1404
1404
@test transform (sdf -> DataFrame (a= 10 )[1 , :], df) == DataFrame (a= [10 , 10 ], b= 3 : 4 , c= 5 : 6 )
@@ -1446,7 +1446,7 @@ end
1446
1446
@test transform! (sdf -> sdf. b, copy (df)) == [df DataFrame (x1= 3 : 4 )]
1447
1447
@test transform! (sdf -> (b = 2 sdf. b,), copy (df)) == DataFrame (a= 1 : 2 , b= [6 , 8 ], c= 5 : 6 )
1448
1448
@test transform! (sdf -> (b = 1 ,), copy (df)) == DataFrame (a= [1 , 2 ], b= [1 , 1 ], c= [5 , 6 ])
1449
- @test_throws ArgumentError transform! (sdf -> (b = [1 ],), copy (df))
1449
+ @test_throws DimensionMismatch transform! (sdf -> (b = [1 ],), copy (df))
1450
1450
@test transform! (sdf -> (b = [1 , 5 ],), copy (df)) == DataFrame (a= [1 , 2 ], b= [1 , 5 ], c= [5 , 6 ])
1451
1451
@test transform! (sdf -> 1 , copy (df)) == DataFrame (a= 1 : 2 , b= 3 : 4 , c= 5 : 6 , x1= 1 )
1452
1452
@test transform! (sdf -> fill ([1 ]), copy (df)) == DataFrame (a= 1 : 2 , b= 3 : 4 , c= 5 : 6 , x1= [[1 ], [1 ]])
@@ -1456,8 +1456,8 @@ end
1456
1456
for ret in (DataFrame (), NamedTuple (), zeros (0 , 0 ), DataFrame (t= 1 )[1 , 1 : 0 ])
1457
1457
@test transform! (sdf -> ret, copy (df)) == df
1458
1458
end
1459
- @test_throws ArgumentError transform! (sdf -> DataFrame (a= 10 ), copy (df))
1460
- @test_throws ArgumentError transform! (sdf -> zeros (1 , 2 ), copy (df))
1459
+ @test_throws DimensionMismatch transform! (sdf -> DataFrame (a= 10 ), copy (df))
1460
+ @test_throws DimensionMismatch transform! (sdf -> zeros (1 , 2 ), copy (df))
1461
1461
@test transform! (sdf -> DataFrame (a= [10 , 11 ]), copy (df)) == DataFrame (a= [10 , 11 ], b= 3 : 4 , c= 5 : 6 )
1462
1462
@test transform! (sdf -> [10 11 ; 12 13 ], copy (df)) == DataFrame (a= 1 : 2 , b= 3 : 4 , c= 5 : 6 , x1= [10 , 12 ], x2= [11 , 13 ])
1463
1463
@test transform! (sdf -> DataFrame (a= 10 )[1 , :], copy (df)) == DataFrame (a= [10 , 10 ], b= 3 : 4 , c= 5 : 6 )
@@ -1489,7 +1489,7 @@ end
1489
1489
@test combine (df, :a => (x -> res) => [:p , :q ]) == DataFrame (p= 1 , q= 2 )
1490
1490
@test_throws ArgumentError combine (df, :a => (x -> res) => [:p ])
1491
1491
@test_throws ArgumentError select (df, :a => (x -> res) => AsTable)
1492
- @test_throws ArgumentError transform (df, :a => (x -> res) => AsTable)
1492
+ @test_throws DimensionMismatch transform (df, :a => (x -> res) => AsTable)
1493
1493
end
1494
1494
@test combine (df, :a => ByRow (x -> [x, x+ 1 ]),
1495
1495
:a => ByRow (x -> [x, x+ 1 ]) => AsTable,
@@ -1625,8 +1625,8 @@ end
1625
1625
DataFrame (a1= 1 , a2= 2 , a= 1 : 2 )
1626
1626
@test select (df, :a => (x -> 1 ) => :a1 , :a => (x -> 2 ) => :a2 , [:a ]) ==
1627
1627
DataFrame (a1= 1 , a2= 2 , a= 1 : 2 )
1628
- @test_throws ArgumentError combine (df, :a => (x -> 1 ) => :a1 , :a => (x -> [2 ]) => :a2 , [:a ])
1629
- @test_throws ArgumentError select (df, :a => (x -> 1 ) => :a1 , :a => (x -> [2 ]) => :a2 , [:a ])
1628
+ @test_throws DimensionMismatch combine (df, :a => (x -> 1 ) => :a1 , :a => (x -> [2 ]) => :a2 , [:a ])
1629
+ @test_throws DimensionMismatch select (df, :a => (x -> 1 ) => :a1 , :a => (x -> [2 ]) => :a2 , [:a ])
1630
1630
end
1631
1631
1632
1632
@testset " normalize_selection" begin
0 commit comments