Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RowTable and ColTable #65

Merged
merged 9 commits into from
May 2, 2022
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/src/transforms/builtin.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@ Coalesce
Coerce
```

## RowTable

```@docs
RowTable
```

## ColTable
```@docs
ColTable
```

## Identity

```@docs
Expand Down
2 changes: 2 additions & 0 deletions src/TableTransforms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export
Replace,
Coalesce,
Coerce,
RowTable,
ColTable,
Identity,
Center,
Scale,
Expand Down
2 changes: 2 additions & 0 deletions src/transforms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ include("transforms/rename.jl")
include("transforms/replace.jl")
include("transforms/coalesce.jl")
include("transforms/coerce.jl")
include("transforms/rowtable.jl")
include("transforms/coltable.jl")
include("transforms/identity.jl")
include("transforms/center.jl")
include("transforms/scale.jl")
Expand Down
14 changes: 14 additions & 0 deletions src/transforms/coltable.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# ------------------------------------------------------------------
# Licensed under the MIT License. See LICENSE in the project root.
# ------------------------------------------------------------------

"""
ColTable()

The transform that applies the function `Tables.columntable` to to the input table.
"""
struct ColTable <: Stateless end

apply(::ColTable, table) = Tables.columntable(table), table

revert(::ColTable, newtable, cache) = cache
14 changes: 14 additions & 0 deletions src/transforms/rowtable.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# ------------------------------------------------------------------
# Licensed under the MIT License. See LICENSE in the project root.
# ------------------------------------------------------------------

"""
RowTable()

The transform that applies the function `Tables.rowtable` to to the input table.
"""
struct RowTable <: Stateless end

apply(::RowTable, table) = Tables.rowtable(table), table

revert(::RowTable, newtable, cache) = cache
26 changes: 26 additions & 0 deletions test/transforms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,32 @@
@test rt == rtₒ
end

@testset "RowTable" begin
a = [3, 2, 1, 4, 5, 3]
b = [1, 4, 4, 5, 8, 5]
c = [1, 1, 6, 2, 4, 1]
t = Table(; a, b, c)
T = RowTable()
n, c = apply(T, t)
tₒ = revert(T, n, c)
@test typeof(n) <: Vector
ceferisbarov marked this conversation as resolved.
Show resolved Hide resolved
@test Tables.rowaccess(typeof(n))
juliohm marked this conversation as resolved.
Show resolved Hide resolved
@test typeof(tₒ) <: Table
end

@testset "ColTable" begin
a = [3, 2, 1, 4, 5, 3]
b = [1, 4, 4, 5, 8, 5]
c = [1, 1, 6, 2, 4, 1]
t = Table(; a, b, c)
T = ColTable()
n, c = apply(T, t)
tₒ = revert(T, n, c)
@test typeof(n) <: NamedTuple
@test Tables.columnaccess(typeof(n))
juliohm marked this conversation as resolved.
Show resolved Hide resolved
@test typeof(tₒ) <: Table
end

@testset "Identity" begin
x = rand(4000)
y = rand(4000)
Expand Down