Skip to content

Commit c07d7aa

Browse files
author
Pietro Vertechi
authored
use IndexedTables setcol rather than reinveinting it (#23)
* wip * remove _view * test for setcol
1 parent 5b7b23f commit c07d7aa

File tree

5 files changed

+18
-27
lines changed

5 files changed

+18
-27
lines changed

REQUIRE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
julia 0.6
22
Compat
3-
IndexedTables 0.6
3+
IndexedTables 0.7.2
44
JuliaDB 0.7.0
55
Reexport
66
MacroTools
77
IterTools
8-
Dagger
8+
Dagger

src/transform.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
transformcol(t, s, col) = s in colnames(t) ? setcol(t, s, col) : pushcol(t, s, col)
2-
function transformcol(t, col::NamedTuples.NamedTuple)
3-
for (key, val) in zip(keys(col), values(col))
4-
t = transformcol(t, key, val)
5-
end
6-
t
1+
@deprecate transformcol setcol
2+
3+
function _setcol(t, col::NamedTuples.NamedTuple)
4+
p = ((key => val) for (key, val) in zip(keys(col), values(col)))
5+
setcol(t, p)
76
end
8-
transformcol(t, col::Union{Columns, IndexedTables.AbstractIndexedTable}) = transformcol(t, columns(col))
7+
_setcol(t, col::Union{Columns, IndexedTables.AbstractIndexedTable}) = _setcol(t, columns(col))
8+
_setcol(t, args...) = setcol(t, args...)
99

1010
function transform_vec_helper(args...)
1111
d = gensym()
12-
func = Expr(:(->), d, Expr(:call, :(JuliaDBMeta.transformcol), d, with_helper(d, args[end])))
12+
func = Expr(:(->), d, Expr(:call, :(JuliaDBMeta._setcol), d, with_helper(d, args[end])))
1313
Expr(:call, :(JuliaDBMeta._pipe), func, replace_keywords(args[1:end-1])...)
1414
end
1515

@@ -42,8 +42,8 @@ macro transform_vec(args...)
4242
end
4343

4444
function transform_helper(args...)
45-
d = gensym()
46-
func = Expr(:(->), d, Expr(:call, :(JuliaDBMeta.transformcol), d, map_helper(d, args[end])))
45+
d = gensym()
46+
func = Expr(:(->), d, Expr(:call, :(JuliaDBMeta._setcol), d, map_helper(d, args[end])))
4747
Expr(:call, :(JuliaDBMeta._pipe_chunks), func, args[1:end-1]...)
4848
end
4949

src/utils.jl

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,4 @@ _table(cols::C) where{C<:Columns} =
9292
NextTable{C}(cols, Int[], IndexedTables.Perm[], fill(Nullable{Float64}(), length(cols)), nothing)
9393
_table(c) = c
9494

95-
_view(t, I) = view(t, find(I))
96-
97-
function _view(t::IndexedTables.NextTable, I)
98-
sorted_index = (eltype(I) == Bool) || issorted(I)
99-
table(
100-
view(t.columns, I),
101-
pkey = sorted_index ? t.pkey : Int64[],
102-
copy = false,
103-
presorted = true
104-
)
105-
end
106-
10795
distinct_tuple(args...) = Tuple(IterTools.distinct(args))

src/where.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
function where_vec_helper(args...)
22
d = gensym()
3-
func = Expr(:(->), d, Expr(:call, :(JuliaDBMeta._view), d, with_helper(d, args[end])))
3+
func = Expr(:(->), d, Expr(:call, :(view), d, with_helper(d, args[end])))
44
Expr(:call, :(JuliaDBMeta._pipe), func, replace_keywords(args[1:end-1])...)
55
end
66

@@ -33,7 +33,7 @@ end
3333

3434
function where_helper(args...)
3535
d = gensym()
36-
func = Expr(:(->), d, Expr(:call, :(JuliaDBMeta._view), d, map_helper(d, args[end])))
36+
func = Expr(:(->), d, Expr(:call, :(view), d, map_helper(d, args[end])))
3737
Expr(:call, :(JuliaDBMeta._pipe_chunks), func, args[1:end-1]...)
3838
end
3939

test/runtests.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ end
7575

7676
@testset "transform" begin
7777
t = table([1,2,3], [4,5,6], [0.1, 0.2, 0.3], names = [:x, :y, :z])
78+
@test setcol(t, :x => [2,3,4], :y => [4,5,6]) ==
79+
JuliaDBMeta._setcol(t, :x => [2,3,4], :y => [4,5,6]) ==
80+
JuliaDBMeta._setcol(t, Columns(x = [2,3,4], y = [4,5,6]))
81+
7882
@test (@transform_vec t @NT(a = :x .+ :y)) == pushcol(t, :a, [1,2,3] .+ [4,5,6])
7983
@test @transform_vec(@NT(a = :x .+ :y))(t) == pushcol(t, :a, [1,2,3] .+ [4,5,6])
8084
@test (@transform_vec t @NT(z = :x .+ :y)) == setcol(t, :z, [1,2,3] .+ [4,5,6])
@@ -90,7 +94,6 @@ end
9094
@test (@where_vec t (:x .< 3) .& (:z .== 0.2)) == view(t, [2])
9195
@test @where_vec(t, 1:2) == view(t, 1:2)
9296
@test @where_vec(rows(t), 1:2) == view(t, 1:2)
93-
@test JuliaDBMeta._view(rows(t), 1:2) == view(rows(t), 1:2)
9497
@test @where_vec((:x .< 3) .& (:z .== 0.2))(t) == view(t, [2])
9598
@test (@where t (:x < 3) .& (:z == 0.2)) == view(t, [2])
9699
@test @where((:x < 3) .& (:z == 0.2))(t) == view(t, [2])

0 commit comments

Comments
 (0)