Skip to content

Commit b0c4782

Browse files
committed
Fix issue with single-column tables
1 parent 9402cd6 commit b0c4782

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

src/TableTransforms.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module TableTransforms
77
using Tables
88
using ScientificTypes
99
using Distributions: Normal
10-
using Transducers: Map, foldxt
10+
using Transducers: tcollect
1111
using LinearAlgebra
1212
using Statistics
1313

src/transforms.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ function apply(transform::Colwise, table)
142142
end
143143

144144
# parallel map with multiple threads
145-
vals = foldxt(vcat, Map(colfunc), names)
145+
vals = tcollect(colfunc(n) for n in names)
146146

147147
# new table with transformed columns
148148
𝒯 = (; first.(vals)...) |> Tables.materializer(table)
@@ -172,7 +172,7 @@ function revert(transform::Colwise, newtable, cache)
172172
end
173173

174174
# parallel map with multiple threads
175-
vals = foldxt(vcat, Map(colfunc), 1:length(names))
175+
vals = tcollect(colfunc(i) for i in 1:length(names))
176176

177177
# new table with transformed columns
178178
(; vals...) |> Tables.materializer(newtable)

src/transforms/parallel.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ isrevertible(p::Parallel) = any(isrevertible, p.transforms)
1616
function apply(p::Parallel, table)
1717
# apply transforms in parallel
1818
f(transform) = apply(transform, table)
19-
vals = foldxt(vcat, Map(f), p.transforms)
19+
vals = tcollect(f(t) for t in p.transforms)
2020

2121
# retrieve tables and caches
2222
tables = first.(vals)

test/transforms.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,4 +339,16 @@
339339
n₂ = P₂(t)
340340
@test Tables.matrix(n₁) Tables.matrix(n₂)
341341
end
342+
343+
@testset "Miscellaneous" begin
344+
# make sure transforms work with
345+
# single-column tables
346+
t = Table(x=rand(10000))
347+
n, c = apply(ZScore(), t)
348+
r = revert(ZScore(), n, c)
349+
@test isapprox(mean(n.x), 0.0, atol=1e-8)
350+
@test isapprox(std(n.x), 1.0, atol=1e-8)
351+
@test isapprox(mean(r.x), mean(t.x), atol=1e-8)
352+
@test isapprox(std(r.x), std(t.x), atol=1e-8)
353+
end
342354
end

0 commit comments

Comments
 (0)