Skip to content

Commit

Permalink
improve tables support
Browse files Browse the repository at this point in the history
  • Loading branch information
aplavin committed Jun 17, 2023
1 parent e2f0667 commit 6b23237
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/tables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ function _schema(::Type{T}) where {T<:NTuple{N, Any}} where N
return Tables.Schema{ntuple(identity, N), T}
end

StructArray(cols::Tables.AbstractColumns) = StructArray(Tables.columntable(cols))
StructArray{T}(cols::Tables.AbstractColumns) where {T} = StructArray{T}(Tables.columntable(cols))

function try_compatible_columns(rows::R, s::StructArray) where {R}
Tables.isrowtable(rows) && Tables.columnaccess(rows) || return nothing
T = eltype(rows)
Expand Down
5 changes: 5 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,11 @@ end
# Testing integer column "names":
@test invoke(append!, Tuple{StructVector,Any}, StructArray(([0],)), StructArray(([1],))) ==
StructArray(([0, 1],))

dtab = (a=[1,2],) |> Tables.dictcolumntable
@test StructArray(dtab) == [(a=1,), (a=2,)]
@test StructArray{NamedTuple{(:a,), Tuple{Float64}}}(dtab) == [(a=1.,), (a=2.,)]
@test StructVector{NamedTuple{(:a,), Tuple{Float64}}}(dtab) == [(a=1,), (a=2,)]
end

struct S
Expand Down

0 comments on commit 6b23237

Please sign in to comment.