diff --git a/docs/src/transforms/builtin.md b/docs/src/transforms/builtin.md index 24f4d7db..ecf712c3 100644 --- a/docs/src/transforms/builtin.md +++ b/docs/src/transforms/builtin.md @@ -50,6 +50,17 @@ Coalesce Coerce ``` +## RowTable + +```@docs +RowTable +``` + +## ColTable +```@docs +ColTable +``` + ## Identity ```@docs diff --git a/src/TableTransforms.jl b/src/TableTransforms.jl index 05ceec7f..9c9ff191 100644 --- a/src/TableTransforms.jl +++ b/src/TableTransforms.jl @@ -34,6 +34,8 @@ export Replace, Coalesce, Coerce, + RowTable, + ColTable, Identity, Center, Scale, diff --git a/src/transforms.jl b/src/transforms.jl index 80eb7e19..b56006a9 100644 --- a/src/transforms.jl +++ b/src/transforms.jl @@ -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") diff --git a/src/transforms/coltable.jl b/src/transforms/coltable.jl new file mode 100644 index 00000000..08e64823 --- /dev/null +++ b/src/transforms/coltable.jl @@ -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 diff --git a/src/transforms/rowtable.jl b/src/transforms/rowtable.jl new file mode 100644 index 00000000..dc4f06f7 --- /dev/null +++ b/src/transforms/rowtable.jl @@ -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 diff --git a/test/transforms.jl b/test/transforms.jl index 64f12ffb..cd540fe9 100644 --- a/test/transforms.jl +++ b/test/transforms.jl @@ -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 + @test Tables.rowaccess(n) + @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(n) + @test typeof(tₒ) <: Table + end + @testset "Identity" begin x = rand(4000) y = rand(4000)