Skip to content

Commit

Permalink
Merge branch 'master' into precompile
Browse files Browse the repository at this point in the history
  • Loading branch information
abalkin authored Oct 28, 2017
2 parents 06b98b4 + f4913f7 commit 44c79a0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ install:
- source ./.travis/install.sh
before_script:
- echo '-1"kdb+ "," "sv string .z.o,.z.K,.z.k;exit 0' | $HOME/q/?32/q
- julia -e 'Pkg.add("IterableTables")'
- julia -e 'versioninfo()'
## uncomment the following lines to override the default test script
script:
Expand Down
24 changes: 24 additions & 0 deletions src/table.jl
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ Base.done{T,TS}(iter::K_Table_Iter{T,TS}, state) = state > length(iter)

function K_Table(source)
iter = TableTraits.getiterator(source)
_table(Base.iteratorsize(iter), iter)
end

_table(::Base.IsInfinite, iter) = error("infinite source")
_table(::Base.HasShape, iter) = _table_prealloc(iter)
_table(::Base.HasLength, iter) = _table_prealloc(iter)

function _table_prealloc(iter)
x = K_Table(eltype(iter), length(iter))
for (i, row) in enumerate(iter)
for (j, v) in enumerate(row)
Expand All @@ -113,3 +121,19 @@ function K_Table(source)
end
x
end

function _raw_eltype(T)
exprs = [Expr(:(::), n, eltype(t))
for (n, t) in zip(fieldnames(T), T.types)]
NamedTuples.make_tuple(exprs)
end

function _table(::Base.SizeUnknown, iter)
x = K_Table(eltype(iter), 0)
for row in iter
for (i, v) in enumerate(row)
Q.coldata(x)[i] = push!(x[i], row[i])
end
end
x
end
2 changes: 2 additions & 0 deletions test/table-tests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using TableTraits
using NamedTuples
import IterableTables

@testset "table tests" begin
let x = K_Table(a=[1, 2])
Expand Down Expand Up @@ -49,4 +50,5 @@ end
]
end
@test K_Table([@NT(a=1), @NT(a=2)]) == DataFrame(a=[1,2])
@test K_Table(@NT(a=i) for i in 1:3 if i != 2) == DataFrame(a=[1,3])
end

0 comments on commit 44c79a0

Please sign in to comment.