Skip to content

Commit 5a269ff

Browse files
author
Pietro Vertechi
authored
tables integration (JuliaArrays#12)
* tables integration * tests * removed fallback constructor * update requires * fix requires * add test dependency
1 parent 339eb18 commit 5a269ff

File tree

5 files changed

+34
-1
lines changed

5 files changed

+34
-1
lines changed

REQUIRE

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
julia 0.7-
1+
julia 0.7
2+
Requires

src/StructArrays.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
module StructArrays
22

3+
import Requires
34
export StructArray
45

56
include("structarray.jl")
67
include("utils.jl")
78

9+
function __init__()
10+
Requires.@require Tables="bd369af6-aec1-5ad0-b16a-f7cc5008161c" include("tables.jl")
11+
end
12+
813
end # module

src/tables.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Tables.istable(::Type{<:StructArray}) = true
2+
Tables.rowaccess(::Type{<:StructArray}) = true
3+
Tables.columnaccess(::Type{<:StructArray}) = true
4+
5+
Tables.rows(s::StructArray) = s
6+
Tables.columns(s::StructArray) = columns(s)
7+
8+
@generated function Tables.schema(s::StructArray{T}) where {T}
9+
names = fieldnames(T)
10+
types = map(sym -> fieldtype(T, sym), names)
11+
:(Tables.Schema($names, $types))
12+
end

test/REQUIRE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Tables

test/runtests.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using StructArrays
2+
import Tables
23
using Test
34

45
# write your own tests here
@@ -103,3 +104,16 @@ end
103104
a = StructArray{ComplexF64}(Float64[], Float64[])
104105
@test sort(collect(propertynames(a))) == [:im, :re]
105106
end
107+
108+
@testset "tables" begin
109+
s = StructArray([(a=1, b="test")])
110+
@test Tables.schema(s) == Tables.Schema((:a, :b), (Int, String))
111+
@test Tables.rows(s)[1].a == 1
112+
@test Tables.rows(s)[1].b == "test"
113+
@test Tables.columns(s).a == [1]
114+
@test Tables.columns(s).b == ["test"]
115+
@test Tables.istable(s)
116+
@test Tables.rowaccess(s)
117+
@test Tables.columnaccess(s)
118+
end
119+

0 commit comments

Comments
 (0)