Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix columntable materialization on stored schema #360

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/namedtuples.jl
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,14 @@ function columntable(sch::Schema{names, types}, cols) where {names, types}
end
end

# extremely large tables
columntable(sch::Schema{nothing, nothing}, cols) =
throw(ArgumentError("input table too wide ($(length(sch.names)) columns) to convert to `NamedTuple` of `AbstractVector`s"))
# extremely large tables or schema explicitly stored
function columntable(sch::Schema{nothing, nothing}, cols)
nms = sch.names
if nms !== nothing && length(nms) > SPECIALIZATION_THRESHOLD
throw(ArgumentError("input table too wide ($(length(nms)) columns) to convert to `NamedTuple` of `AbstractVector`s"))
end
return NamedTuple{Tuple(map(Symbol, nms))}(Tuple(getarray(getcolumn(cols, nms[i])) for i = 1:length(nms)))
end

# unknown schema case
columntable(::Nothing, cols) =
Expand Down
11 changes: 11 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1040,3 +1040,14 @@ end
@test DataAPI.nrow(Tables.dictrowtable([(a=1, b=2), (a=3, b=4), (a=5, b=6)])) == 3
@test DataAPI.ncol(Tables.dictrowtable([(a=1, b=2), (a=3, b=4), (a=5, b=6)])) == 2
end

@testset "#357" begin
dct = Tables.dictcolumntable((a=1:3, b=4.0:6.0, c=["7", "8", "9"]))
sch = Tables.schema(dct)
sch = Tables.Schema(sch.names, sch.types, stored=true)
dct = Tables.DictColumnTable(sch, getfield(dct, :values))
nt = Tables.columntable(dct)
@test nt.a == [1, 2, 3]
@test nt.b == [4.0, 5.0, 6.0]
@test nt.c == ["7", "8", "9"]
end
Loading