Skip to content

Commit 1cb9b72

Browse files
author
Pietro Vertechi
committed
decouple from tables
1 parent 363b22c commit 1cb9b72

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

src/tables.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ Tables.isrowtable(::Type{<:StructArray}) = true
22

33
Tables.columnaccess(::Type{<:StructArray}) = true
44
Tables.columns(s::StructArray) = fieldarrays(s)
5-
Tables.getcolumn(s::StructArray, i::Int) = getproperty(s, i)
65
Tables.schema(s::StructArray) = Tables.Schema(staticschema(eltype(s)))
76

87
function Base.append!(s::StructVector, rows)

src/utils.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ function buildfromschema(initializer, ::Type{T}, ::Type{NT}) where {T, NT<:Tup}
2121
StructArray{T}(nt)
2222
end
2323

24+
@static if VERSION < v"1.2.0"
25+
@inline _getproperty(v::Tuple, field) = getfield(v, field)
26+
@inline _getproperty(v, field) = getproperty(v, field)
27+
else
28+
const _getproperty = getproperty
29+
end
30+
2431
function _foreachfield(names, L)
2532
vars = ntuple(i -> gensym(), L)
2633
exprs = Expr[]
@@ -29,7 +36,7 @@ function _foreachfield(names, L)
2936
end
3037
for field in names
3138
sym = QuoteNode(field)
32-
args = [Expr(:call, :getcolumn, var, sym) for var in vars]
39+
args = [Expr(:call, :_getproperty, var, sym) for var in vars]
3340
push!(exprs, Expr(:call, :f, args...))
3441
end
3542
push!(exprs, :(return nothing))

test/runtests.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -336,10 +336,10 @@ end
336336
@test Tables.rowaccess(typeof(s))
337337
@test Tables.columnaccess(s)
338338
@test Tables.columnaccess(typeof(s))
339-
@test Tables.getcolumn(s, 1) == [1]
340-
@test Tables.getcolumn(s, :a) == [1]
341-
@test Tables.getcolumn(s, 2) == ["test"]
342-
@test Tables.getcolumn(s, :b) == ["test"]
339+
@test Tables.getcolumn(Tables.columns(s), 1) == [1]
340+
@test Tables.getcolumn(Tables.columns(s), :a) == [1]
341+
@test Tables.getcolumn(Tables.columns(s), 2) == ["test"]
342+
@test Tables.getcolumn(Tables.columns(s), :b) == ["test"]
343343
@test append!(StructArray([1im]), [(re = 111, im = 222)]) ==
344344
StructArray([1im, 111 + 222im])
345345
@test append!(StructArray([1im]), (x for x in [(re = 111, im = 222)])) ==

0 commit comments

Comments
 (0)