@@ -237,142 +237,142 @@ StructArrays.SkipConstructor(::Type{<:S}) = true
237
237
end
238
238
239
239
const initializer = StructArrays. ArrayInitializer (t -> t <: Union{Tuple, NamedTuple, Pair} )
240
- collect_fieldarrays_rec (t) = StructArrays. collect_fieldarrays (t, initializer = initializer)
240
+ collect_structarray_rec (t) = StructArrays. collect_structarray (t, initializer = initializer)
241
241
242
242
@testset " collectnamedtuples" begin
243
243
v = [(a = 1 , b = 2 ), (a = 1 , b = 3 )]
244
- collect_fieldarrays_rec (v) == StructArray ((a = Int[1 , 1 ], b = Int[2 , 3 ]))
244
+ collect_structarray_rec (v) == StructArray ((a = Int[1 , 1 ], b = Int[2 , 3 ]))
245
245
246
246
# test inferrability with constant eltype
247
247
itr = [(a = 1 , b = 2 ), (a = 1 , b = 2 ), (a = 1 , b = 12 )]
248
248
el, st = iterate (itr)
249
249
dest = initializer (typeof (el), (3 ,))
250
250
dest[1 ] = el
251
- @inferred StructArrays. collect_to_fieldarrays ! (dest, itr, 2 , st)
251
+ @inferred StructArrays. collect_to_structarray ! (dest, itr, 2 , st)
252
252
253
253
v = [(a = 1 , b = 2 ), (a = 1.2 , b = 3 )]
254
- @test collect_fieldarrays_rec (v) == StructArray ((a = [1 , 1.2 ], b = Int[2 , 3 ]))
255
- @test typeof (collect_fieldarrays_rec (v)) == typeof (StructArray ((a = [1 , 1.2 ], b = Int[2 , 3 ])))
254
+ @test collect_structarray_rec (v) == StructArray ((a = [1 , 1.2 ], b = Int[2 , 3 ]))
255
+ @test typeof (collect_structarray_rec (v)) == typeof (StructArray ((a = [1 , 1.2 ], b = Int[2 , 3 ])))
256
256
257
257
s = StructArray (a = [1 , 2 ], b = [3 , 4 ])
258
- @test StructArrays. collect_fieldarrays (LazyRow (s, i) for i in eachindex (s)) == s
259
- @test collect_fieldarrays_rec (LazyRow (s, i) for i in eachindex (s)) == s
258
+ @test StructArrays. collect_structarray (LazyRow (s, i) for i in eachindex (s)) == s
259
+ @test collect_structarray_rec (LazyRow (s, i) for i in eachindex (s)) == s
260
260
261
261
v = [(a = 1 , b = 2 ), (a = 1.2 , b = " 3" )]
262
- @test collect_fieldarrays_rec (v) == StructArray ((a = [1 , 1.2 ], b = Any[2 , " 3" ]))
263
- @test typeof (collect_fieldarrays_rec (v)) == typeof (StructArray ((a = [1 , 1.2 ], b = Any[2 , " 3" ])))
262
+ @test collect_structarray_rec (v) == StructArray ((a = [1 , 1.2 ], b = Any[2 , " 3" ]))
263
+ @test typeof (collect_structarray_rec (v)) == typeof (StructArray ((a = [1 , 1.2 ], b = Any[2 , " 3" ])))
264
264
265
265
v = [(a = 1 , b = 2 ), (a = 1.2 , b = 2 ), (a = 1 , b = " 3" )]
266
- @test collect_fieldarrays_rec (v) == StructArray ((a = [1 , 1.2 , 1 ], b = Any[2 , 2 , " 3" ]))
267
- @test typeof (collect_fieldarrays_rec (v)) == typeof (StructArray ((a = [1 , 1.2 , 1 ], b = Any[2 , 2 , " 3" ])))
266
+ @test collect_structarray_rec (v) == StructArray ((a = [1 , 1.2 , 1 ], b = Any[2 , 2 , " 3" ]))
267
+ @test typeof (collect_structarray_rec (v)) == typeof (StructArray ((a = [1 , 1.2 , 1 ], b = Any[2 , 2 , " 3" ])))
268
268
269
269
# length unknown
270
270
itr = Iterators. filter (isodd, 1 : 8 )
271
271
tuple_itr = ((a = i+ 1 , b = i- 1 ) for i in itr)
272
- @test collect_fieldarrays_rec (tuple_itr) == StructArray ((a = [2 , 4 , 6 , 8 ], b = [0 , 2 , 4 , 6 ]))
272
+ @test collect_structarray_rec (tuple_itr) == StructArray ((a = [2 , 4 , 6 , 8 ], b = [0 , 2 , 4 , 6 ]))
273
273
tuple_itr_real = (i == 1 ? (a = 1.2 , b = i- 1 ) : (a = i+ 1 , b = i- 1 ) for i in itr)
274
- @test collect_fieldarrays_rec (tuple_itr_real) == StructArray ((a = Real[1.2 , 4 , 6 , 8 ], b = [0 , 2 , 4 , 6 ]))
274
+ @test collect_structarray_rec (tuple_itr_real) == StructArray ((a = Real[1.2 , 4 , 6 , 8 ], b = [0 , 2 , 4 , 6 ]))
275
275
276
276
# empty
277
277
itr = Iterators. filter (t -> t > 10 , 1 : 8 )
278
278
tuple_itr = ((a = i+ 1 , b = i- 1 ) for i in itr)
279
- @test collect_fieldarrays_rec (tuple_itr) == StructArray ((a = Int[], b = Int[]))
279
+ @test collect_structarray_rec (tuple_itr) == StructArray ((a = Int[], b = Int[]))
280
280
281
281
itr = (i for i in 0 : - 1 )
282
282
tuple_itr = ((a = i+ 1 , b = i- 1 ) for i in itr)
283
- @test collect_fieldarrays_rec (tuple_itr) == StructArray ((a = Int[], b = Int[]))
283
+ @test collect_structarray_rec (tuple_itr) == StructArray ((a = Int[], b = Int[]))
284
284
end
285
285
286
286
@testset " collecttuples" begin
287
287
v = [(1 , 2 ), (1 , 3 )]
288
- @test collect_fieldarrays_rec (v) == StructArray ((Int[1 , 1 ], Int[2 , 3 ]))
289
- @inferred collect_fieldarrays_rec (v)
288
+ @test collect_structarray_rec (v) == StructArray ((Int[1 , 1 ], Int[2 , 3 ]))
289
+ @inferred collect_structarray_rec (v)
290
290
291
- @test StructArrays. collect_fieldarrays (v) == StructArray ((Int[1 , 1 ], Int[2 , 3 ]))
292
- @inferred StructArrays. collect_fieldarrays (v)
291
+ @test StructArrays. collect_structarray (v) == StructArray ((Int[1 , 1 ], Int[2 , 3 ]))
292
+ @inferred StructArrays. collect_structarray (v)
293
293
294
294
v = [(1 , 2 ), (1.2 , 3 )]
295
- @test collect_fieldarrays_rec (v) == StructArray (([1 , 1.2 ], Int[2 , 3 ]))
295
+ @test collect_structarray_rec (v) == StructArray (([1 , 1.2 ], Int[2 , 3 ]))
296
296
297
297
v = [(1 , 2 ), (1.2 , " 3" )]
298
- @test collect_fieldarrays_rec (v) == StructArray (([1 , 1.2 ], Any[2 , " 3" ]))
299
- @test typeof (collect_fieldarrays_rec (v)) == typeof (StructArray (([1 , 1.2 ], Any[2 , " 3" ])))
298
+ @test collect_structarray_rec (v) == StructArray (([1 , 1.2 ], Any[2 , " 3" ]))
299
+ @test typeof (collect_structarray_rec (v)) == typeof (StructArray (([1 , 1.2 ], Any[2 , " 3" ])))
300
300
301
301
v = [(1 , 2 ), (1.2 , 2 ), (1 , " 3" )]
302
- @test collect_fieldarrays_rec (v) == StructArray (([1 , 1.2 , 1 ], Any[2 , 2 , " 3" ]))
302
+ @test collect_structarray_rec (v) == StructArray (([1 , 1.2 , 1 ], Any[2 , 2 , " 3" ]))
303
303
# length unknown
304
304
itr = Iterators. filter (isodd, 1 : 8 )
305
305
tuple_itr = ((i+ 1 , i- 1 ) for i in itr)
306
- @test collect_fieldarrays_rec (tuple_itr) == StructArray (([2 , 4 , 6 , 8 ], [0 , 2 , 4 , 6 ]))
306
+ @test collect_structarray_rec (tuple_itr) == StructArray (([2 , 4 , 6 , 8 ], [0 , 2 , 4 , 6 ]))
307
307
tuple_itr_real = (i == 1 ? (1.2 , i- 1 ) : (i+ 1 , i- 1 ) for i in itr)
308
- @test collect_fieldarrays_rec (tuple_itr_real) == StructArray (([1.2 , 4 , 6 , 8 ], [0 , 2 , 4 , 6 ]))
309
- @test typeof (collect_fieldarrays_rec (tuple_itr_real)) == typeof (StructArray (([1.2 , 4 , 6 , 8 ], [0 , 2 , 4 , 6 ])))
308
+ @test collect_structarray_rec (tuple_itr_real) == StructArray (([1.2 , 4 , 6 , 8 ], [0 , 2 , 4 , 6 ]))
309
+ @test typeof (collect_structarray_rec (tuple_itr_real)) == typeof (StructArray (([1.2 , 4 , 6 , 8 ], [0 , 2 , 4 , 6 ])))
310
310
311
311
# empty
312
312
itr = Iterators. filter (t -> t > 10 , 1 : 8 )
313
313
tuple_itr = ((i+ 1 , i- 1 ) for i in itr)
314
- @test collect_fieldarrays_rec (tuple_itr) == StructArray ((Int[], Int[]))
314
+ @test collect_structarray_rec (tuple_itr) == StructArray ((Int[], Int[]))
315
315
316
316
itr = (i for i in 0 : - 1 )
317
317
tuple_itr = ((i+ 1 , i- 1 ) for i in itr)
318
- @test collect_fieldarrays_rec (tuple_itr) == StructArray ((Int[], Int[]))
318
+ @test collect_structarray_rec (tuple_itr) == StructArray ((Int[], Int[]))
319
319
end
320
320
321
321
@testset " collectscalars" begin
322
322
v = (i for i in 1 : 3 )
323
- @test collect_fieldarrays_rec (v) == [1 ,2 ,3 ]
324
- @inferred collect_fieldarrays_rec (v)
323
+ @test collect_structarray_rec (v) == [1 ,2 ,3 ]
324
+ @inferred collect_structarray_rec (v)
325
325
326
326
v = (i == 1 ? 1.2 : i for i in 1 : 3 )
327
- @test collect_fieldarrays_rec (v) == collect (v)
327
+ @test collect_structarray_rec (v) == collect (v)
328
328
329
329
itr = Iterators. filter (isodd, 1 : 100 )
330
- @test collect_fieldarrays_rec (itr) == collect (itr)
330
+ @test collect_structarray_rec (itr) == collect (itr)
331
331
real_itr = (i == 1 ? 1.5 : i for i in itr)
332
- @test collect_fieldarrays_rec (real_itr) == collect (real_itr)
333
- @test eltype (collect_fieldarrays_rec (real_itr)) == Float64
332
+ @test collect_structarray_rec (real_itr) == collect (real_itr)
333
+ @test eltype (collect_structarray_rec (real_itr)) == Float64
334
334
335
335
# empty
336
336
itr = Iterators. filter (t -> t > 10 , 1 : 8 )
337
337
tuple_itr = (exp (i) for i in itr)
338
- @test collect_fieldarrays_rec (tuple_itr) == Float64[]
338
+ @test collect_structarray_rec (tuple_itr) == Float64[]
339
339
340
340
itr = (i for i in 0 : - 1 )
341
341
tuple_itr = (exp (i) for i in itr)
342
- @test collect_fieldarrays_rec (tuple_itr) == Float64[]
342
+ @test collect_structarray_rec (tuple_itr) == Float64[]
343
343
344
- t = collect_fieldarrays_rec ((a = i,) for i in (1 , missing , 3 ))
344
+ t = collect_structarray_rec ((a = i,) for i in (1 , missing , 3 ))
345
345
@test StructArrays. fieldarrays (t)[1 ] isa Array{Union{Int, Missing}}
346
346
@test isequal (StructArrays. fieldarrays (t)[1 ], [1 , missing , 3 ])
347
347
end
348
348
349
349
@testset " collectpairs" begin
350
350
v = (i=> i+ 1 for i in 1 : 3 )
351
- @test collect_fieldarrays_rec (v) == StructArray {Pair{Int, Int}} ([1 ,2 ,3 ], [2 ,3 ,4 ])
352
- @test eltype (collect_fieldarrays_rec (v)) == Pair{Int, Int}
351
+ @test collect_structarray_rec (v) == StructArray {Pair{Int, Int}} ([1 ,2 ,3 ], [2 ,3 ,4 ])
352
+ @test eltype (collect_structarray_rec (v)) == Pair{Int, Int}
353
353
354
354
v = (i == 1 ? (1.2 => i+ 1 ) : (i => i+ 1 ) for i in 1 : 3 )
355
- @test collect_fieldarrays_rec (v) == StructArray {Pair{Float64, Int}} ([1.2 ,2 ,3 ], [2 ,3 ,4 ])
356
- @test eltype (collect_fieldarrays_rec (v)) == Pair{Float64, Int}
355
+ @test collect_structarray_rec (v) == StructArray {Pair{Float64, Int}} ([1.2 ,2 ,3 ], [2 ,3 ,4 ])
356
+ @test eltype (collect_structarray_rec (v)) == Pair{Float64, Int}
357
357
358
358
v = ((a= i,) => (b= " a$i " ,) for i in 1 : 3 )
359
- @test collect_fieldarrays_rec (v) == StructArray{Pair{NamedTuple{(:a ,),Tuple{Int64}},NamedTuple{(:b ,),Tuple{String}}}}(StructArray ((a = [1 ,2 ,3 ],)), StructArray ((b = [" a1" ," a2" ," a3" ],)))
360
- @test eltype (collect_fieldarrays_rec (v)) == Pair{NamedTuple{(:a ,), Tuple{Int64}}, NamedTuple{(:b ,), Tuple{String}}}
359
+ @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" ],)))
360
+ @test eltype (collect_structarray_rec (v)) == Pair{NamedTuple{(:a ,), Tuple{Int64}}, NamedTuple{(:b ,), Tuple{String}}}
361
361
362
362
v = (i == 1 ? (a= " 1" ,) => (b= " a$i " ,) : (a= i,) => (b= " a$i " ,) for i in 1 : 3 )
363
- @test collect_fieldarrays_rec (v) == StructArray{Pair{NamedTuple{(:a ,),Tuple{Any}},NamedTuple{(:b ,),Tuple{String}}}}(StructArray ((a = [" 1" ,2 ,3 ],)), StructArray ((b = [" a1" ," a2" ," a3" ],)))
364
- @test eltype (collect_fieldarrays_rec (v)) == Pair{NamedTuple{(:a ,), Tuple{Any}}, NamedTuple{(:b ,), Tuple{String}}}
363
+ @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" ],)))
364
+ @test eltype (collect_structarray_rec (v)) == Pair{NamedTuple{(:a ,), Tuple{Any}}, NamedTuple{(:b ,), Tuple{String}}}
365
365
366
366
# empty
367
367
v = ((a= i,) => (b= " a$i " ,) for i in 0 : - 1 )
368
- @test collect_fieldarrays_rec (v) == StructArray{Pair{NamedTuple{(:a ,),Tuple{Int64}},NamedTuple{(:b ,),Tuple{String}}}}(StructArray ((a = Int[],)), StructArray ((b = String[],)))
369
- @test eltype (collect_fieldarrays_rec (v)) == Pair{NamedTuple{(:a ,), Tuple{Int}}, NamedTuple{(:b ,), Tuple{String}}}
368
+ @test collect_structarray_rec (v) == StructArray{Pair{NamedTuple{(:a ,),Tuple{Int64}},NamedTuple{(:b ,),Tuple{String}}}}(StructArray ((a = Int[],)), StructArray ((b = String[],)))
369
+ @test eltype (collect_structarray_rec (v)) == Pair{NamedTuple{(:a ,), Tuple{Int}}, NamedTuple{(:b ,), Tuple{String}}}
370
370
371
371
v = Iterators. filter (t -> t. first. a == 4 , ((a= i,) => (b= " a$i " ,) for i in 1 : 3 ))
372
- @test collect_fieldarrays_rec (v) == StructArray{Pair{NamedTuple{(:a ,),Tuple{Int64}},NamedTuple{(:b ,),Tuple{String}}}}(StructArray ((a = Int[],)), StructArray ((b = String[],)))
373
- @test eltype (collect_fieldarrays_rec (v)) == Pair{NamedTuple{(:a ,), Tuple{Int}}, NamedTuple{(:b ,), Tuple{String}}}
372
+ @test collect_structarray_rec (v) == StructArray{Pair{NamedTuple{(:a ,),Tuple{Int64}},NamedTuple{(:b ,),Tuple{String}}}}(StructArray ((a = Int[],)), StructArray ((b = String[],)))
373
+ @test eltype (collect_structarray_rec (v)) == Pair{NamedTuple{(:a ,), Tuple{Int}}, NamedTuple{(:b ,), Tuple{String}}}
374
374
375
- t = collect_fieldarrays_rec ((b = 1 ,) => (a = i,) for i in (2 , missing , 3 ))
375
+ t = collect_structarray_rec ((b = 1 ,) => (a = i,) for i in (2 , missing , 3 ))
376
376
s = StructArray{Pair{NamedTuple{(:b ,),Tuple{Int64}},NamedTuple{(:a ,),Tuple{Union{Missing, Int64}}}}}(StructArray (b = [1 ,1 ,1 ]), StructArray (a = [2 , missing , 3 ]))
377
377
@test s[1 ] == t[1 ]
378
378
@test ismissing (t[2 ]. second. a)
381
381
382
382
@testset " collect2D" begin
383
383
s = (l for l in [(a= i, b= j) for i in 1 : 3 , j in 1 : 4 ])
384
- v = StructArrays. collect_fieldarrays (s)
384
+ v = StructArrays. collect_structarray (s)
385
385
@test size (v) == (3 , 4 )
386
386
@test v. a == [i for i in 1 : 3 , j in 1 : 4 ]
387
387
@test v. b == [j for i in 1 : 3 , j in 1 : 4 ]
0 commit comments