diff --git a/src/fallbacks.jl b/src/fallbacks.jl index bdcbfa5..40bb554 100644 --- a/src/fallbacks.jl +++ b/src/fallbacks.jl @@ -73,11 +73,11 @@ end @inline add!(dest::AbstractVector, val, T, row) = push!(dest, val) @inline function add_or_widen!(dest::AbstractVector{T}, val::S, nm::Symbol, L, row, len, updated) where {T, S} - if S === T || val isa T + if S === T || promote_type(S, T) <: T add!(dest, val, L, row) return dest else - new = allocatecolumn(Base.promote_typejoin(T, S), max(len, length(dest))) + new = allocatecolumn(promote_type(T, S), max(len, length(dest))) row > 1 && copyto!(new, 1, dest, 1, row - 1) add!(new, val, L, row) updated[] = merge(updated[], NamedTuple{(nm,)}((new,))) diff --git a/src/namedtuples.jl b/src/namedtuples.jl index b0e947f..a1fedbf 100644 --- a/src/namedtuples.jl +++ b/src/namedtuples.jl @@ -40,7 +40,7 @@ function Base.iterate(rows::NamedTupleIterator{Nothing, T}, st=()) where {T} x = iterate(rows.x, st...) x === nothing && return nothing row, st = x - names = propertynames(row) + names = Tuple(propertynames(row)) return NamedTuple{names}(Tuple(getproperty(row, nm) for nm in names)), (st,) end diff --git a/test/runtests.jl b/test/runtests.jl index 4363ea7..f1ad220 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -97,7 +97,11 @@ end @test length(rt2) == 9 rt = [(a=1, b=4.0, c="7"), (a=2.0, b=missing, c="8"), (a=3, b=6.0, c="9")] - @test isequal(Tables.buildcolumns(nothing, rt), (a = Real[1, 2.0, 3], b = Union{Missing, Float64}[4.0, missing, 6.0], c = ["7", "8", "9"])) + tt = Tables.buildcolumns(nothing, rt) + @test isequal(tt, (a = [1.0, 2.0, 3.0], b = Union{Missing, Float64}[4.0, missing, 6.0], c = ["7", "8", "9"])) + @test tt.a[1] === 1.0 + @test tt.a[2] === 2.0 + @test tt.a[3] === 3.0 nti = Tables.NamedTupleIterator{Nothing, typeof(rt)}(rt) nti2 = collect(nti)