@@ -72,14 +72,14 @@ module TestCat
72
72
dt[1 : 2 , 1 : 2 ] = [3 ,2 ]
73
73
dt[[true ,false ,false ,true ], 2 : 3 ] = [2 ,3 ]
74
74
75
- vcat ([] )
76
- vcat (null_dt)
77
- vcat (null_dt, null_dt )
78
- vcat (null_dt, dt )
79
- vcat (dt, null_dt)
80
- vcat (dt, dt)
81
- vcat (dt, dt, dt)
82
- @test vcat (DataTable[]) == DataTable ( )
75
+ @test vcat (null_dt) == DataTable ( )
76
+ @test vcat (null_dt, null_dt) == DataTable ( )
77
+ @test_throws ArgumentError vcat (null_dt, dt )
78
+ @test_throws ArgumentError vcat (dt, null_dt )
79
+ @test eltypes ( vcat (dt, dt)) == [Nullable{Float64}, Nullable{Float64}, Nullable{Int}]
80
+ @test size ( vcat (dt, dt)) == ( size (dt, 1 ) * 2 , size (dt, 2 ) )
81
+ @test eltypes ( vcat (dt, dt, dt)) == [Nullable{Float64}, Nullable{Float64}, Nullable{Int}]
82
+ @test size ( vcat (dt, dt, dt)) == ( size (dt, 1 ) * 3 , size (dt, 2 ) )
83
83
84
84
alt_dt = deepcopy (dt)
85
85
vcat (dt, alt_dt)
@@ -88,29 +88,13 @@ module TestCat
88
88
dt[1 ] = zeros (Int, nrow (dt))
89
89
vcat (dt, alt_dt)
90
90
91
- # Don't fail on non-matching names
92
- names! (alt_dt, [:A , :B , :C ])
93
- vcat (dt, alt_dt)
94
-
95
91
dtr = vcat (dt4, dt4)
96
92
@test size (dtr, 1 ) == 8
97
93
@test names (dt4) == names (dtr)
98
94
@test isequal (dtr, [dt4; dt4])
99
95
100
- dtr = vcat (dt2, dt3)
101
- @test size (dtr) == (8 ,2 )
102
- @test names (dt2) == names (dtr)
103
- @test isnull (dtr[8 ,:x2 ])
104
-
105
- # Eltype promotion
106
- # Fails on Julia 0.4 since promote_type(Nullable{Int}, Nullable{Float64}) gives Nullable{T}
107
- if VERSION >= v " 0.5.0-dev"
108
- @test eltypes (vcat (DataTable (a = [1 ]), DataTable (a = [2.1 ]))) == [Nullable{Float64}]
109
- @test eltypes (vcat (DataTable (a = NullableArray (Int, 1 )), DataTable (a = [2.1 ]))) == [Nullable{Float64}]
110
- else
111
- @test eltypes (vcat (DataTable (a = [1 ]), DataTable (a = [2.1 ]))) == [Nullable{Any}]
112
- @test eltypes (vcat (DataTable (a = NullableArray (Int, 1 )), DataTable (a = [2.1 ]))) == [Nullable{Any}]
113
- end
96
+ @test eltypes (vcat (DataTable (a = [1 ]), DataTable (a = [2.1 ]))) == [Nullable{Float64}]
97
+ @test eltypes (vcat (DataTable (a = NullableArray (Int, 1 )), DataTable (a = [2.1 ]))) == [Nullable{Float64}]
114
98
115
99
# Minimal container type promotion
116
100
dta = DataTable (a = CategoricalArray ([1 , 2 , 2 ]))
@@ -122,12 +106,7 @@ module TestCat
122
106
@test isequal (dtab[:a ], Nullable{Int}[1 , 2 , 2 , 2 , 3 , 4 ])
123
107
@test isequal (dtac[:a ], Nullable{Int}[1 , 2 , 2 , 2 , 3 , 4 ])
124
108
@test isa (dtab[:a ], NullableCategoricalVector{Int})
125
- # Fails on Julia 0.4 since promote_type(Nullable{Int}, Nullable{Float64}) gives Nullable{T}
126
- if VERSION >= v " 0.5.0-dev"
127
- @test isa (dtac[:a ], NullableCategoricalVector{Int})
128
- else
129
- @test isa (dtac[:a ], NullableCategoricalVector{Any})
130
- end
109
+ @test isa (dtac[:a ], NullableCategoricalVector{Int})
131
110
# ^^ container may flip if container promotion happens in Base/DataArrays
132
111
dc = vcat (dtd, dtc)
133
112
@test isequal (vcat (dtc, dtd), dc)
@@ -137,15 +116,120 @@ module TestCat
137
116
@test isequal (vcat (dtd, dtc0, dtc), dc)
138
117
@test eltypes (vcat (dtd, dtc0)) == eltypes (dc)
139
118
140
- # Missing columns
141
- rename! (dtd, :a , :b )
142
- dtda = DataTable (b = NullableArray (Nullable{Int}[2 , 3 , 4 , Nullable (), Nullable (), Nullable ()]),
143
- a = NullableCategoricalVector (Nullable{Int}[Nullable (), Nullable (), Nullable (), 1 , 2 , 2 ]))
144
- @test isequal (vcat (dtd, dta), dtda)
145
-
146
- # Alignment
147
- @test isequal (vcat (dtda, dtd, dta), vcat (dtda, dtda))
148
-
149
119
# vcat should be able to concatenate different implementations of AbstractDataTable (PR #944)
150
120
@test isequal (vcat (view (DataTable (A= 1 : 3 ),2 ),DataTable (A= 4 : 5 )), DataTable (A= [2 ,4 ,5 ]))
121
+
122
+ @testset " vcat >2 args" begin
123
+ @test vcat (DataTable (), DataTable (), DataTable ()) == DataTable ()
124
+ dt = DataTable (x = trues (1 ), y = falses (1 ))
125
+ @test vcat (dt, dt, dt) == DataTable (x = trues (3 ), y = falses (3 ))
126
+ end
127
+
128
+ @testset " vcat mixed coltypes" begin
129
+ drf = CategoricalArrays. DefaultRefType
130
+ dt = vcat (DataTable ([[1 ]], [:x ]), DataTable ([[1.0 ]], [:x ]))
131
+ @test dt == DataTable ([[1.0 , 1.0 ]], [:x ])
132
+ @test typeof .(dt. columns) == [Vector{Float64}]
133
+ dt = vcat (DataTable ([[1 ]], [:x ]), DataTable ([[" 1" ]], [:x ]))
134
+ @test dt == DataTable ([[1 , " 1" ]], [:x ])
135
+ @test typeof .(dt. columns) == [Vector{Any}]
136
+ dt = vcat (DataTable ([NullableArray ([1 ])], [:x ]), DataTable ([[1 ]], [:x ]))
137
+ @test dt == DataTable ([NullableArray ([1 , 1 ])], [:x ])
138
+ @test typeof .(dt. columns) == [NullableVector{Int}]
139
+ dt = vcat (DataTable ([CategoricalArray ([1 ])], [:x ]), DataTable ([[1 ]], [:x ]))
140
+ @test dt == DataTable ([CategoricalArray ([1 , 1 ])], [:x ])
141
+ @test typeof .(dt. columns) == [CategoricalVector{Int, drf}]
142
+ dt = vcat (DataTable ([CategoricalArray ([1 ])], [:x ]),
143
+ DataTable ([NullableArray ([1 ])], [:x ]))
144
+ @test dt == DataTable ([NullableCategoricalArray ([1 , 1 ])], [:x ])
145
+ @test typeof .(dt. columns) == [NullableCategoricalVector{Int, drf}]
146
+ dt = vcat (DataTable ([CategoricalArray ([1 ])], [:x ]),
147
+ DataTable ([NullableCategoricalArray ([1 ])], [:x ]))
148
+ @test dt == DataTable ([NullableCategoricalArray ([1 , 1 ])], [:x ])
149
+ @test typeof .(dt. columns) == [NullableCategoricalVector{Int, drf}]
150
+ dt = vcat (DataTable ([NullableArray ([1 ])], [:x ]),
151
+ DataTable ([NullableArray ([" 1" ])], [:x ]))
152
+ @test dt == DataTable ([NullableArray ([1 , " 1" ])], [:x ])
153
+ @test typeof .(dt. columns) == [NullableVector{Any}]
154
+ dt = vcat (DataTable ([CategoricalArray ([1 ])], [:x ]),
155
+ DataTable ([CategoricalArray ([" 1" ])], [:x ]))
156
+ @test dt == DataTable ([CategoricalArray ([1 , " 1" ])], [:x ])
157
+ @test typeof .(dt. columns) == [CategoricalVector{Any, drf}]
158
+ dt = vcat (DataTable ([trues (1 )], [:x ]), DataTable ([[false ]], [:x ]))
159
+ @test dt == DataTable ([[true , false ]], [:x ])
160
+ @test typeof .(dt. columns) == [Vector{Bool}]
161
+ end
162
+
163
+ @testset " vcat errors" begin
164
+ err = @test_throws ArgumentError vcat (DataTable (), DataTable (), DataTable (x= []))
165
+ @test err. value. msg == " column(s) x are missing from argument(s) 1 and 2"
166
+ err = @test_throws ArgumentError vcat (DataTable (), DataTable (), DataTable (x= [1 ]))
167
+ @test err. value. msg == " column(s) x are missing from argument(s) 1 and 2"
168
+ dt1 = DataTable (A = 1 : 3 , B = 1 : 3 )
169
+ dt2 = DataTable (A = 1 : 3 )
170
+ # right missing 1 column
171
+ err = @test_throws ArgumentError vcat (dt1, dt2)
172
+ @test err. value. msg == " column(s) B are missing from argument(s) 2"
173
+ # left missing 1 column
174
+ err = @test_throws ArgumentError vcat (dt2, dt1)
175
+ @test err. value. msg == " column(s) B are missing from argument(s) 1"
176
+ # multiple missing 1 column
177
+ err = @test_throws ArgumentError vcat (dt1, dt2, dt2, dt2, dt2, dt2)
178
+ @test err. value. msg == " column(s) B are missing from argument(s) 2, 3, 4, 5 and 6"
179
+ # argument missing >1 columns
180
+ dt1 = DataTable (A = 1 : 3 , B = 1 : 3 , C = 1 : 3 , D = 1 : 3 , E = 1 : 3 )
181
+ err = @test_throws ArgumentError vcat (dt1, dt2)
182
+ @test err. value. msg == " column(s) B, C, D and E are missing from argument(s) 2"
183
+ # >1 arguments missing >1 columns
184
+ err = @test_throws ArgumentError vcat (dt1, dt2, dt2, dt2, dt2)
185
+ @test err. value. msg == " column(s) B, C, D and E are missing from argument(s) 2, 3, 4 and 5"
186
+ # out of order
187
+ dt2 = dt1[reverse (names (dt1))]
188
+ err = @test_throws ArgumentError vcat (dt1, dt2)
189
+ @test err. value. msg == " column order of argument(s) 1 != column order of argument(s) 2"
190
+ # first group >1 arguments
191
+ err = @test_throws ArgumentError vcat (dt1, dt1, dt2)
192
+ @test err. value. msg == " column order of argument(s) 1 and 2 != column order of argument(s) 3"
193
+ # second group >1 arguments
194
+ err = @test_throws ArgumentError vcat (dt1, dt2, dt2)
195
+ @test err. value. msg == " column order of argument(s) 1 != column order of argument(s) 2 and 3"
196
+ # first and second groups >1 argument
197
+ err = @test_throws ArgumentError vcat (dt1, dt1, dt1, dt2, dt2, dt2)
198
+ @test err. value. msg == " column order of argument(s) 1, 2 and 3 != column order of argument(s) 4, 5 and 6"
199
+ # >2 groups out of order
200
+ srand (1 )
201
+ dt3 = dt1[shuffle (names (dt1))]
202
+ err = @test_throws ArgumentError vcat (dt1, dt1, dt1, dt2, dt2, dt2, dt3, dt3, dt3, dt3)
203
+ @test err. value. msg == " column order of argument(s) 1, 2 and 3 != column order of argument(s) 4, 5 and 6 != column order of argument(s) 7, 8, 9 and 10"
204
+ # missing columns throws error before out of order columns
205
+ dt1 = DataTable (A = 1 , B = 1 )
206
+ dt2 = DataTable (A = 1 )
207
+ dt3 = DataTable (B = 1 , A = 1 )
208
+ err = @test_throws ArgumentError vcat (dt1, dt2, dt3)
209
+ @test err. value. msg == " column(s) B are missing from argument(s) 2"
210
+ # unique columns for both sides
211
+ dt1 = DataTable (A = 1 , B = 1 , C = 1 , D = 1 )
212
+ dt2 = DataTable (A = 1 , C = 1 , D = 1 , E = 1 , F = 1 )
213
+ err = @test_throws ArgumentError vcat (dt1, dt2)
214
+ @test err. value. msg == " column(s) E and F are missing from argument(s) 1, and column(s) B are missing from argument(s) 2"
215
+ err = @test_throws ArgumentError vcat (dt1, dt1, dt2, dt2)
216
+ @test err. value. msg == " column(s) E and F are missing from argument(s) 1 and 2, and column(s) B are missing from argument(s) 3 and 4"
217
+ dt3 = DataTable (A = 1 , B = 1 , C = 1 , D = 1 , E = 1 )
218
+ err = @test_throws ArgumentError vcat (dt1, dt2, dt3)
219
+ @test err. value. msg == " column(s) E and F are missing from argument(s) 1, column(s) B are missing from argument(s) 2, and column(s) F are missing from argument(s) 3"
220
+ err = @test_throws ArgumentError vcat (dt1, dt1, dt2, dt2, dt3, dt3)
221
+ @test err. value. msg == " column(s) E and F are missing from argument(s) 1 and 2, column(s) B are missing from argument(s) 3 and 4, and column(s) F are missing from argument(s) 5 and 6"
222
+ err = @test_throws ArgumentError vcat (dt1, dt1, dt1, dt2, dt2, dt2, dt3, dt3, dt3)
223
+ @test err. value. msg == " column(s) E and F are missing from argument(s) 1, 2 and 3, column(s) B are missing from argument(s) 4, 5 and 6, and column(s) F are missing from argument(s) 7, 8 and 9"
224
+ # dt4 is a superset of names found in all other datatables and won't be shown in error
225
+ dt4 = DataTable (A = 1 , B = 1 , C = 1 , D = 1 , E = 1 , F = 1 )
226
+ err = @test_throws ArgumentError vcat (dt1, dt2, dt3, dt4)
227
+ @test err. value. msg == " column(s) E and F are missing from argument(s) 1, column(s) B are missing from argument(s) 2, and column(s) F are missing from argument(s) 3"
228
+ err = @test_throws ArgumentError vcat (dt1, dt1, dt2, dt2, dt3, dt3, dt4, dt4)
229
+ @test err. value. msg == " column(s) E and F are missing from argument(s) 1 and 2, column(s) B are missing from argument(s) 3 and 4, and column(s) F are missing from argument(s) 5 and 6"
230
+ err = @test_throws ArgumentError vcat (dt1, dt1, dt1, dt2, dt2, dt2, dt3, dt3, dt3, dt4, dt4, dt4)
231
+ @test err. value. msg == " column(s) E and F are missing from argument(s) 1, 2 and 3, column(s) B are missing from argument(s) 4, 5 and 6, and column(s) F are missing from argument(s) 7, 8 and 9"
232
+ err = @test_throws ArgumentError vcat (dt1, dt2, dt3, dt4, dt1, dt2, dt3, dt4, dt1, dt2, dt3, dt4)
233
+ @test err. value. msg == " column(s) E and F are missing from argument(s) 1, 5 and 9, column(s) B are missing from argument(s) 2, 6 and 10, and column(s) F are missing from argument(s) 3, 7 and 11"
234
+ end
151
235
end
0 commit comments