@@ -302,6 +302,7 @@ module TestDataFrame
302
302
levels! (df[1 ], [" XXX" , " Bob" , " Batman" ])
303
303
# Unstack specifying a row column
304
304
df2 = unstack (df, :Fish , :Key , :Value )
305
+ @test levels (df[1 ]) == [" XXX" , " Bob" , " Batman" ] # make sure we did not mess df[1] levels
305
306
# Unstack without specifying a row column
306
307
df3 = unstack (df, :Key , :Value )
307
308
# The expected output, XXX level should be dropped as it has no rows with this key
@@ -385,8 +386,8 @@ module TestDataFrame
385
386
id2= Union{Int, Missing}[1 , 2 , 1 , 2 ],
386
387
variable= [" a" , " b" , " a" , " b" ], value= [3 , 4 , 5 , 6 ])
387
388
@static if VERSION >= v " 0.6.0-dev.1980"
388
- @test_warn " Duplicate entries in unstack at row 3 for key '1' and variable 'a' ." unstack (df, :id , :variable , :value )
389
- @test_warn " Duplicate entries in unstack at row 3 for key ' (1, 1)' and variable 'a' ." unstack (df, :variable , :value )
389
+ @test_warn " Duplicate entries in unstack at row 3 for key 1 and variable a ." unstack (df, :id , :variable , :value )
390
+ @test_warn " Duplicate entries in unstack at row 3 for key (1, 1) and variable a ." unstack (df, :variable , :value )
390
391
end
391
392
a = unstack (df, :id , :variable , :value )
392
393
@test a ≅ DataFrame (id = [1 , 2 ], a = [5 , missing ], b = [missing , 6 ])
@@ -403,20 +404,20 @@ module TestDataFrame
403
404
@test a ≅ b ≅ DataFrame (id = [1 , 2 ], a = [3 , missing ], b = [missing , 4 ])
404
405
405
406
df = DataFrame (variable= [" x" , " x" ], value= [missing , missing ], id= [1 ,1 ])
406
- @test_warn " Duplicate entries in unstack at row 2." unstack (df, :variable , :value )
407
- @test_warn " Duplicate entries in unstack at row 2." unstack (df)
407
+ @test_warn " Duplicate entries in unstack at row 2 for key 1 and variable x ." unstack (df, :variable , :value )
408
+ @test_warn " Duplicate entries in unstack at row 2 for key 1 and variable x ." unstack (df)
408
409
end
409
410
410
411
@testset " missing values in colkey" begin
411
412
df = DataFrame (id= [1 , 1 , 1 , missing , missing , missing , 2 , 2 , 2 ],
412
413
variable= [" a" , " b" , missing , " a" , " b" , " missing" , " a" , " b" , " missing" ],
413
414
value= [missing , 2.0 , 3.0 , 4.0 , 5.0 , missing , 7.0 , missing , 9.0 ])
414
- @test_warn " Missing value in ' variable' variable at row 3. Skipping." unstack (df)
415
+ @test_warn " Missing value in variable variable at row 3. Skipping." unstack (df)
415
416
df = DataFrame (id= [1 , 1 , 1 , missing , missing , missing , 2 , 2 , 2 ],
416
417
id2= [1 , 1 , 1 , missing , missing , missing , 2 , 2 , 2 ],
417
418
variable= [" a" , " b" , missing , " a" , " b" , " missing" , " a" , " b" , " missing" ],
418
419
value= [missing , 2.0 , 3.0 , 4.0 , 5.0 , missing , 7.0 , missing , 9.0 ])
419
- @test_warn " Missing value in ' variable' variable at row 3. Skipping." unstack (df, 3 , 4 )
420
+ @test_warn " Missing value in variable variable at row 3. Skipping." unstack (df, 3 , 4 )
420
421
end
421
422
422
423
@testset " stack-unstack correctness" begin
0 commit comments