Skip to content

Commit 37db140

Browse files
authored
Fix fallback case on empty input iterators with abstract eltypes (#229)
Fixes #228. We recently added support so that when a schema-less input row table was being converted to column-orientation, but had an eltype, we produced an appropriately typed NamedTuple with empty Vectors of corresponding types. The issue reported, however, is when an empty input has an eltype, but that eltype is abstract. The error results by trying to call `fieldcount(::AbstractType)`, which fails and doesn't make sense to do anyway. This is technically a regression because we used to produce an empty `NamedTuple()` unconditionally, and now we're producing this error path for the abstract eltype case. The fix proposed is straightforward: only consider generating a typed NamedTuple output if the iterator eltype is concretely typed.
1 parent cfc4984 commit 37db140

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/fallbacks.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ end
203203
WT = wrappedtype(eltype(rowitr))
204204
if WT <: Tuple
205205
return allocatecolumns(Schema((Symbol("Column$i") for i = 1:fieldcount(WT)), _fieldtypes(WT)), 0)
206-
elseif fieldcount(WT) > 0
206+
elseif isconcretetype(WT) && fieldcount(WT) > 0
207207
return allocatecolumns(Schema(fieldnames(WT), _fieldtypes(WT)), 0)
208208
end
209209
end

test/runtests.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ end
169169
@test eltype(rt).parameters[1] == nms
170170
@test Tables.columntable(rt) == nt
171171
@test Tables.buildcolumns(nothing, rt) == nt
172+
173+
# 228
174+
@test Tables.columntable(NamedTuple[]) === NamedTuple()
172175
end
173176

174177
@testset "Materializer" begin

0 commit comments

Comments
 (0)