125
125
@test s[1 ] == (1 , " test" )
126
126
@test Base. getproperty (s, 1 ) == [1 ]
127
127
@test Base. getproperty (s, 2 ) == [" test" ]
128
- t = StructArray {Tuple{Int, Float64}} ([1 ], [1.2 ])
128
+ t = StructArray {Tuple{Int, Float64}} (( [1 ], [1.2 ]) )
129
129
@test t[1 ] == (1 , 1.2 )
130
130
131
131
t[1 ] = (2 , 3 )
@@ -139,26 +139,26 @@ end
139
139
a = [1.2 ]
140
140
b = [2.3 ]
141
141
@test StructArray (a= a, b= b) == StructArray ((a= a, b= b))
142
- @test StructArray {ComplexF64} (re= a, im= b) == StructArray {ComplexF64} (a, b)
142
+ @test StructArray {ComplexF64} (re= a, im= b) == StructArray {ComplexF64} (( a, b) )
143
143
f1 () = StructArray (a= [1.2 ], b= [" test" ])
144
144
f2 () = StructArray {Pair} (first= [1.2 ], second= [" test" ])
145
145
t1 = @inferred f1 ()
146
146
t2 = @inferred f2 ()
147
147
@test t1 == StructArray ((a= [1.2 ], b= [" test" ]))
148
- @test t2 == StructArray {Pair} ([1.2 ], [" test" ])
148
+ @test t2 == StructArray {Pair} (( [1.2 ], [" test" ]) )
149
149
end
150
150
151
151
@testset " complex" begin
152
152
a, b = [1 2 ; 3 4 ], [4 5 ; 6 7 ]
153
- t = StructArray {ComplexF64} (a, b)
153
+ t = StructArray {ComplexF64} (( a, b) )
154
154
@test t[2 ,2 ] == ComplexF64 (4 , 7 )
155
- @test t[2 ,1 : 2 ] == StructArray {ComplexF64} ([3 , 4 ], [6 , 7 ])
156
- @test view (t, 2 , 1 : 2 ) == StructArray {ComplexF64} (view (a, 2 , 1 : 2 ), view (b, 2 , 1 : 2 ))
155
+ @test t[2 ,1 : 2 ] == StructArray {ComplexF64} (( [3 , 4 ], [6 , 7 ]) )
156
+ @test view (t, 2 , 1 : 2 ) == StructArray {ComplexF64} (( view (a, 2 , 1 : 2 ), view (b, 2 , 1 : 2 ) ))
157
157
end
158
158
159
159
@testset " copy" begin
160
160
a, b = [1 2 ; 3 4 ], [4 5 ; 6 7 ]
161
- t = StructArray {ComplexF64} (a, b)
161
+ t = StructArray {ComplexF64} (( a, b) )
162
162
t2 = @inferred copy (t)
163
163
@test t2[1 ,1 ] == 1.0 + im* 4.0
164
164
t2[1 ,1 ] = 2.0 + im* 4.0
176
176
end
177
177
178
178
@testset " resize!" begin
179
- t = StructArray {Pair} ([3 , 5 ], [" a" , " b" ])
179
+ t = StructArray {Pair} (( [3 , 5 ], [" a" , " b" ]) )
180
180
resize! (t, 5 )
181
181
@test length (t) == 5
182
182
p = 1 => " c"
@@ -185,23 +185,24 @@ end
185
185
end
186
186
187
187
@testset " concat" begin
188
- t = StructArray {Pair} ([3 , 5 ], [" a" , " b" ])
188
+ t = StructArray {Pair} (( [3 , 5 ], [" a" , " b" ]) )
189
189
push! (t, (2 => " c" ))
190
- @test t == StructArray {Pair} ([3 , 5 , 2 ], [" a" , " b" , " c" ])
190
+ @test t == StructArray {Pair} (( [3 , 5 , 2 ], [" a" , " b" , " c" ]) )
191
191
append! (t, t)
192
- @test t == StructArray {Pair} ([3 , 5 , 2 , 3 , 5 , 2 ], [" a" , " b" , " c" , " a" , " b" , " c" ])
193
- t = StructArray {Pair} ([3 , 5 ], [" a" , " b" ])
194
- t2 = StructArray {Pair} ([1 , 6 ], [" a" , " b" ])
195
- @test cat (t, t2; dims= 1 ):: StructArray == StructArray {Pair} ([3 , 5 , 1 , 6 ], [" a" , " b" , " a" , " b" ]) == vcat (t, t2)
192
+ @test t == StructArray {Pair} (( [3 , 5 , 2 , 3 , 5 , 2 ], [" a" , " b" , " c" , " a" , " b" , " c" ]) )
193
+ t = StructArray {Pair} (( [3 , 5 ], [" a" , " b" ]) )
194
+ t2 = StructArray {Pair} (( [1 , 6 ], [" a" , " b" ]) )
195
+ @test cat (t, t2; dims= 1 ):: StructArray == StructArray {Pair} (( [3 , 5 , 1 , 6 ], [" a" , " b" , " a" , " b" ]) ) == vcat (t, t2)
196
196
@test vcat (t, t2) isa StructArray
197
- @test cat (t, t2; dims= 2 ):: StructArray == StructArray {Pair} ([3 1 ; 5 6 ], [" a" " a" ; " b" " b" ]) == hcat (t, t2)
197
+ @test cat (t, t2; dims= 2 ):: StructArray == StructArray {Pair} (( [3 1 ; 5 6 ], [" a" " a" ; " b" " b" ]) ) == hcat (t, t2)
198
198
@test hcat (t, t2) isa StructArray
199
199
end
200
200
201
- f_infer () = StructArray {ComplexF64} (rand (2 ,2 ), rand (2 ,2 ))
201
+ f_infer () = StructArray {ComplexF64} (( rand (2 ,2 ), rand (2 ,2 ) ))
202
202
203
203
g_infer () = StructArray ([(a= (b= " 1" ,), c= 2 )], unwrap = t -> t <: NamedTuple )
204
204
tup_infer () = StructArray ([(1 , 2 ), (3 , 4 )])
205
+ cols_infer () = StructArray (([1 , 2 ], [1.2 , 2.3 ]))
205
206
206
207
@testset " inferrability" begin
207
208
@inferred f_infer ()
@@ -211,10 +212,11 @@ tup_infer() = StructArray([(1, 2), (3, 4)])
211
212
@test Tables. columns (s) == (x1 = [1 , 3 ], x2 = [2 , 4 ])
212
213
@test s[1 ] == (1 , 2 )
213
214
@test s[2 ] == (3 , 4 )
215
+ @inferred cols_infer ()
214
216
end
215
217
216
218
@testset " propertynames" begin
217
- a = StructArray {ComplexF64} (Float64[], Float64[])
219
+ a = StructArray {ComplexF64} (( Float64[], Float64[]) )
218
220
@test sort (collect (propertynames (a))) == [:im , :re ]
219
221
end
220
222
239
241
StructArrays. SkipConstructor (:: Type{<:S} ) = true
240
242
241
243
@testset " inner" begin
242
- v = StructArray {S} ([1 ], [1 ])
244
+ v = StructArray {S} (( [1 ], [1 ]) )
243
245
@test v[1 ] == S (1 )
244
246
@test v[1 ]. y isa Float64
245
247
end
@@ -367,32 +369,32 @@ end
367
369
368
370
@testset " collectpairs" begin
369
371
v = (i=> i+ 1 for i in 1 : 3 )
370
- @test collect_structarray_rec (v) == StructArray {Pair{Int, Int}} ([1 ,2 ,3 ], [2 ,3 ,4 ])
372
+ @test collect_structarray_rec (v) == StructArray {Pair{Int, Int}} (( [1 ,2 ,3 ], [2 ,3 ,4 ]) )
371
373
@test eltype (collect_structarray_rec (v)) == Pair{Int, Int}
372
374
373
375
v = (i == 1 ? (1.2 => i+ 1 ) : (i => i+ 1 ) for i in 1 : 3 )
374
- @test collect_structarray_rec (v) == StructArray {Pair{Real, Int}} ([1.2 ,2 ,3 ], [2 ,3 ,4 ])
376
+ @test collect_structarray_rec (v) == StructArray {Pair{Real, Int}} (( [1.2 ,2 ,3 ], [2 ,3 ,4 ]) )
375
377
@test eltype (collect_structarray_rec (v)) == Pair{Real, Int}
376
378
377
379
v = ((a= i,) => (b= " a$i " ,) for i in 1 : 3 )
378
- @test collect_structarray_rec (v) == StructArray{Pair{NamedTuple{( :a ,),Tuple{Int64}},NamedTuple{( :b ,),Tuple{String}}}}( StructArray ((a = [1 ,2 ,3 ],)), StructArray ((b = [" a1" ," a2" ," a3" ],)))
380
+ @test collect_structarray_rec (v) == StructArray ( StructArray ((a = [1 ,2 ,3 ],)) => StructArray ((b = [" a1" ," a2" ," a3" ],)))
379
381
@test eltype (collect_structarray_rec (v)) == Pair{NamedTuple{(:a ,), Tuple{Int64}}, NamedTuple{(:b ,), Tuple{String}}}
380
382
381
383
v = (i == 1 ? (a= " 1" ,) => (b= " a$i " ,) : (a= i,) => (b= " a$i " ,) for i in 1 : 3 )
382
- @test collect_structarray_rec (v) == StructArray{Pair{NamedTuple{( :a ,),Tuple{Any}},NamedTuple{( :b ,),Tuple{String}}}}( StructArray ((a = [" 1" ,2 ,3 ],)), StructArray ((b = [" a1" ," a2" ," a3" ],)))
384
+ @test collect_structarray_rec (v) == StructArray ( StructArray ((a = [" 1" ,2 ,3 ],)) => StructArray ((b = [" a1" ," a2" ," a3" ],)))
383
385
@test eltype (collect_structarray_rec (v)) == Pair{NamedTuple{(:a ,), Tuple{Any}}, NamedTuple{(:b ,), Tuple{String}}}
384
386
385
387
# empty
386
388
v = ((a= i,) => (b= " a$i " ,) for i in 0 : - 1 )
387
- @test collect_structarray_rec (v) == StructArray{Pair{NamedTuple{( :a ,),Tuple{Int64}},NamedTuple{( :b ,),Tuple{String}}}}( StructArray ((a = Int[],)), StructArray ((b = String[],)))
389
+ @test collect_structarray_rec (v) == StructArray ( StructArray ((a = Int[],)) => StructArray ((b = String[],)))
388
390
@test eltype (collect_structarray_rec (v)) == Pair{NamedTuple{(:a ,), Tuple{Int}}, NamedTuple{(:b ,), Tuple{String}}}
389
391
390
392
v = Iterators. filter (t -> t. first. a == 4 , ((a= i,) => (b= " a$i " ,) for i in 1 : 3 ))
391
- @test collect_structarray_rec (v) == StructArray{Pair{NamedTuple{( :a ,),Tuple{Int64}},NamedTuple{( :b ,),Tuple{String}}}}( StructArray ((a = Int[],)), StructArray ((b = String[],)))
393
+ @test collect_structarray_rec (v) == StructArray ( StructArray ((a = Int[],)) => StructArray ((b = String[],)))
392
394
@test eltype (collect_structarray_rec (v)) == Pair{NamedTuple{(:a ,), Tuple{Int}}, NamedTuple{(:b ,), Tuple{String}}}
393
395
394
396
t = collect_structarray_rec ((b = 1 ,) => (a = i,) for i in (2 , missing , 3 ))
395
- s = StructArray{Pair{NamedTuple{( :b ,),Tuple{Int64}},NamedTuple{( :a ,),Tuple{Union{Missing, Int64}}}}}( StructArray (b = [1 ,1 ,1 ]), StructArray (a = [2 , missing , 3 ]))
397
+ s = StructArray ( StructArray (b = [1 ,1 ,1 ]) => StructArray (a = [2 , missing , 3 ]))
396
398
@test s[1 ] == t[1 ]
397
399
@test ismissing (t[2 ]. second. a)
398
400
@test s[3 ] == t[3 ]
0 commit comments