1
- module TestData
2
- importall Base # so that we get warnings for conflicts
3
- using Base. Test
4
- using DataFrames
5
- using Compat. String
6
-
7
- # test_group("NullableArray creation")
8
- nvint = NullableArray (Nullable{Int}[1 , 2 , Nullable (), 4 ])
9
- nvint2 = NullableArray (5 : 8 )
10
- nvint3 = NullableArray (5 : 8 )
11
- nvflt = NullableArray (Nullable{Float64}[1.0 , 2.0 , Nullable (), 4.0 ])
12
- nvstr = NullableArray (Nullable{String}[" one" , " two" , Nullable (), " four" ])
13
- dvdict = NullableArray (Dict, 4 ) # for issue #199
14
-
15
- # test_group("constructors")
16
- df1 = DataFrame (Any[nvint, nvstr], [:Ints , :Strs ])
17
- df2 = DataFrame (Any[nvint, nvstr])
18
- df3 = DataFrame (Any[nvint])
19
- df4 = convert (DataFrame, [1 : 4 1 : 4 ])
20
- df5 = DataFrame (Any[NullableArray ([1 ,2 ,3 ,4 ]), nvstr])
21
- df6 = DataFrame (Any[nvint, nvint, nvstr], [:A , :B , :C ])
22
- df7 = DataFrame (x = nvint, y = nvstr)
23
- @test size (df7) == (4 , 2 )
24
- @test isequal (df7[:x ], nvint)
25
-
26
- # test_group("description functions")
27
- @test size (df6, 1 ) == 4
28
- @test size (df6, 2 ) == 3
29
- @test names (df6) == [:A , :B , :C ]
30
- @test names (df2) == [:x1 , :x2 ]
31
- @test names (df7) == [:x , :y ]
32
-
33
- # test_group("ref")
1
+ @testset " Assorted DataFrame tests" begin # TODO redistribute/remove?
2
+
3
+ # NullableArray creation
4
+ nvint = NullableArray (Nullable{Int}[1 , 2 , Nullable (), 4 ])
5
+ nvint2 = NullableArray (5 : 8 )
6
+ nvint3 = NullableArray (5 : 8 )
7
+ nvflt = NullableArray (Nullable{Float64}[1.0 , 2.0 , Nullable (), 4.0 ])
8
+ nvstr = NullableArray (Nullable{String}[" one" , " two" , Nullable (), " four" ])
9
+ dvdict = NullableArray (Dict, 4 ) # for issue #199
10
+
11
+ # constructors
12
+ df1 = DataFrame (Any[nvint, nvstr], [:Ints , :Strs ])
13
+ df2 = DataFrame (Any[nvint, nvstr])
14
+ df3 = DataFrame (Any[nvint])
15
+ df4 = convert (DataFrame, [1 : 4 1 : 4 ])
16
+ df5 = DataFrame (Any[NullableArray ([1 ,2 ,3 ,4 ]), nvstr])
17
+ df6 = DataFrame (Any[nvint, nvint, nvstr], [:A , :B , :C ])
18
+ df7 = DataFrame (x = nvint, y = nvstr)
19
+ @test size (df7) == (4 , 2 )
20
+ @test isequal (df7[:x ], nvint)
21
+
22
+ # description functions
23
+ @test size (df6, 1 ) == 4
24
+ @test size (df6, 2 ) == 3
25
+ @test names (df6) == [:A , :B , :C ]
26
+ @test names (df2) == [:x1 , :x2 ]
27
+ @test names (df7) == [:x , :y ]
28
+
29
+ @testset " ref" begin
34
30
@test isequal (df6[2 , 3 ], Nullable (" two" ))
35
31
@test isnull (df6[3 , 3 ])
36
32
@test isequal (df6[2 , :C ], Nullable (" two" ))
@@ -41,8 +37,9 @@ module TestData
41
37
@test size (df6[1 : 2 , 1 : 2 ]) == (2 , 2 )
42
38
@test size (head (df6,2 )) == (2 , 3 )
43
39
# lots more to do
40
+ end
44
41
45
- # test_group( "assign")
42
+ @testset " assign" begin
46
43
df6[3 ] = NullableArray ([" un" , " deux" , " troix" , " quatre" ])
47
44
@test isequal (df6[1 , 3 ], Nullable (" un" ))
48
45
df6[:B ] = [4 , 3 , 2 , 1 ]
@@ -52,12 +49,13 @@ module TestData
52
49
delete! (df6, :D )
53
50
@test names (df6) == [:A , :B , :C ]
54
51
@test size (df6, 2 ) == 3
52
+ end
55
53
56
- # test_group( "null handling")
54
+ @testset " null handling" begin
57
55
@test nrow (df5[complete_cases (df5), :]) == 3
56
+ end
58
57
59
- # test_context("SubDataFrames")
60
-
58
+ @testset " SubDataFrame" begin
61
59
# test_group("constructors")
62
60
# single index is rows
63
61
sdf6a = sub (df6, 1 )
@@ -69,11 +67,12 @@ module TestData
69
67
70
68
# test_group("ref")
71
69
@test isequal (sdf6a[1 ,2 ], Nullable (4 ))
70
+ end
72
71
73
72
# test_context("Within")
74
73
# test_group("Associative")
75
74
76
- # test_group("DataFrame")
75
+ @testset " Grouping " begin
77
76
srand (1 )
78
77
N = 20
79
78
# Cast to Int64 as rand() behavior differs between Int32/64
@@ -83,7 +82,6 @@ module TestData
83
82
d4 = NullableArray (randn (N))
84
83
df7 = DataFrame (Any[d1, d2, d3], [:d1 , :d2 , :d3 ])
85
84
86
- # test_group("groupby")
87
85
gd = groupby (df7, :d1 )
88
86
@test isa (gd, GroupedDataFrame)
89
87
@test length (gd) == 2
@@ -133,8 +131,9 @@ module TestData
133
131
@test ggd[1 ][2 , :d4 ] == " c"
134
132
@test ggd[2 ][1 , :d3 ] == " a"
135
133
@test ggd[2 ][1 , :d4 ] == " d"
134
+ end
136
135
137
- # test_group( "reshape")
136
+ @testset " reshape" begin
138
137
d1 = DataFrame (a = repeat ([1 : 3 ;], inner = [4 ]),
139
138
b = repeat ([1 : 4 ;], inner = [3 ]),
140
139
c = randn (12 ),
@@ -175,9 +174,9 @@ module TestData
175
174
@test isequal (d1us[:a ], d1[:a ])
176
175
@test isequal (d1us2[:d ], d1[:d ])
177
176
@test isequal (d1us2[:3 ], d1[:d ])
177
+ end
178
178
179
-
180
-
179
+ @testset " join" begin
181
180
d2 = DataFrame (id1 = [:a , :a , :a , :b ],
182
181
id2 = [:A , :B , :B , :B ],
183
182
id3 = [:t , :f , :t , :f ],
@@ -225,22 +224,23 @@ module TestData
225
224
m4 = join (df1, df2, on = :a , kind = :outer )
226
225
@test isequal (m4[:a ], NullableArray ([1 , 2 , 3 , 4 ]))
227
226
228
- # test with nulls (issue #185)
229
- df1 = DataFrame ()
230
- df1[:A ] = NullableArray (Nullable{Compat. ASCIIString}[" a" , " b" , " a" , Nullable ()])
231
- df1[:B ] = NullableArray ([1 , 2 , 1 , 3 ])
227
+ @testset " test with nulls (issue #185)" begin
228
+ df1 = DataFrame ()
229
+ df1[:A ] = NullableArray (Nullable{Compat. ASCIIString}[" a" , " b" , " a" , Nullable ()])
230
+ df1[:B ] = NullableArray ([1 , 2 , 1 , 3 ])
232
231
233
- df2 = DataFrame ()
234
- df2[:A ] = NullableArray (Nullable{Compat. ASCIIString}[" a" , Nullable (), " c" ])
235
- df2[:C ] = NullableArray ([1 , 2 , 4 ])
232
+ df2 = DataFrame ()
233
+ df2[:A ] = NullableArray (Nullable{Compat. ASCIIString}[" a" , Nullable (), " c" ])
234
+ df2[:C ] = NullableArray ([1 , 2 , 4 ])
236
235
237
- m1 = join (df1, df2, on = :A )
238
- @test size (m1) == (3 ,3 )
239
- @test isequal (m1[:A ], NullableArray (Nullable{Compat. ASCIIString}[" a" ," a" ,Nullable ()]))
236
+ m1 = join (df1, df2, on = :A )
237
+ @test size (m1) == (3 ,3 )
238
+ @test isequal (m1[:A ], NullableArray (Nullable{Compat. ASCIIString}[" a" ," a" ,Nullable ()]))
240
239
241
- m2 = join (df1, df2, on = :A , kind = :outer )
242
- @test size (m2) == (5 ,3 )
243
- @test isequal (m2[:A ], NullableArray (Nullable{Compat. ASCIIString}[" a" ," b" ," a" ,Nullable ()," c" ]))
240
+ m2 = join (df1, df2, on = :A , kind = :outer )
241
+ @test size (m2) == (5 ,3 )
242
+ @test isequal (m2[:A ], NullableArray (Nullable{Compat. ASCIIString}[" a" ," b" ," a" ,Nullable ()," c" ]))
243
+ end
244
244
245
245
srand (1 )
246
246
df1 = DataFrame (
@@ -265,7 +265,9 @@ module TestData
265
265
# NullableArray(Nullable{String}["x", "x", "y", "y",
266
266
# "x", "x", "x", "x", "x", "y",
267
267
# Nullable(), "y"])
268
+ end
268
269
270
+ @testset " unique" begin
269
271
srand (1 )
270
272
function spltdf (d)
271
273
d[:x1 ] = map (x -> get (x)[1 ], d[:a ])
@@ -313,3 +315,5 @@ module TestData
313
315
unique! (df, [1 , 3 ])
314
316
@test isequal (df, df1)
315
317
end
318
+
319
+ end
0 commit comments