Skip to content

Commit 735e507

Browse files
authored
Merge pull request #65 from ceferisbarov/rowtable
Add RowTable and ColTable
2 parents 6363d8f + 048cf63 commit 735e507

File tree

6 files changed

+69
-0
lines changed

6 files changed

+69
-0
lines changed

docs/src/transforms/builtin.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,17 @@ Coalesce
5050
Coerce
5151
```
5252

53+
## RowTable
54+
55+
```@docs
56+
RowTable
57+
```
58+
59+
## ColTable
60+
```@docs
61+
ColTable
62+
```
63+
5364
## Identity
5465

5566
```@docs

src/TableTransforms.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ export
3434
Replace,
3535
Coalesce,
3636
Coerce,
37+
RowTable,
38+
ColTable,
3739
Identity,
3840
Center,
3941
Scale,

src/transforms.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@ include("transforms/rename.jl")
217217
include("transforms/replace.jl")
218218
include("transforms/coalesce.jl")
219219
include("transforms/coerce.jl")
220+
include("transforms/rowtable.jl")
221+
include("transforms/coltable.jl")
220222
include("transforms/identity.jl")
221223
include("transforms/center.jl")
222224
include("transforms/scale.jl")

src/transforms/coltable.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# ------------------------------------------------------------------
2+
# Licensed under the MIT License. See LICENSE in the project root.
3+
# ------------------------------------------------------------------
4+
5+
"""
6+
ColTable()
7+
8+
The transform that applies the function `Tables.columntable` to to the input table.
9+
"""
10+
struct ColTable <: Stateless end
11+
12+
apply(::ColTable, table) = Tables.columntable(table), table
13+
14+
revert(::ColTable, newtable, cache) = cache

src/transforms/rowtable.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# ------------------------------------------------------------------
2+
# Licensed under the MIT License. See LICENSE in the project root.
3+
# ------------------------------------------------------------------
4+
5+
"""
6+
RowTable()
7+
8+
The transform that applies the function `Tables.rowtable` to to the input table.
9+
"""
10+
struct RowTable <: Stateless end
11+
12+
apply(::RowTable, table) = Tables.rowtable(table), table
13+
14+
revert(::RowTable, newtable, cache) = cache

test/transforms.jl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,32 @@
859859
@test rt == rtₒ
860860
end
861861

862+
@testset "RowTable" begin
863+
a = [3, 2, 1, 4, 5, 3]
864+
b = [1, 4, 4, 5, 8, 5]
865+
c = [1, 1, 6, 2, 4, 1]
866+
t = Table(; a, b, c)
867+
T = RowTable()
868+
n, c = apply(T, t)
869+
tₒ = revert(T, n, c)
870+
@test typeof(n) <: Vector
871+
@test Tables.rowaccess(n)
872+
@test typeof(tₒ) <: Table
873+
end
874+
875+
@testset "ColTable" begin
876+
a = [3, 2, 1, 4, 5, 3]
877+
b = [1, 4, 4, 5, 8, 5]
878+
c = [1, 1, 6, 2, 4, 1]
879+
t = Table(; a, b, c)
880+
T = ColTable()
881+
n, c = apply(T, t)
882+
tₒ = revert(T, n, c)
883+
@test typeof(n) <: NamedTuple
884+
@test Tables.columnaccess(n)
885+
@test typeof(tₒ) <: Table
886+
end
887+
862888
@testset "Identity" begin
863889
x = rand(4000)
864890
y = rand(4000)

0 commit comments

Comments
 (0)