Skip to content

Commit b1c3bfc

Browse files
authored
Fix revert for ParallelTableTrasform (#146)
* Fix revert for ParallelTableTrasform * Update test/metadata.jl * Add more tests * Fix tests for VarMeta * Improve docstring for ParallelTableTransform
1 parent 186ac74 commit b1c3bfc

File tree

2 files changed

+44
-7
lines changed

2 files changed

+44
-7
lines changed

src/transforms/parallel.jl

+13-7
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,22 @@
66
ParallelTableTransform(transforms)
77
88
A transform where `transforms` are applied in parallel.
9+
It [`isrevertible`](@ref) if any of the constituent
10+
`transforms` is revertible. In this case, the
11+
[`revert`](@ref) is performed with the first
12+
revertible transform in the list.
913
1014
# Examples
1115
1216
```julia
1317
Scale(low=0.3, high=0.6) ⊔ EigenAnalysis(:VDV)
1418
ZScore() ⊔ EigenAnalysis(:V)
1519
```
20+
21+
### Notes
22+
23+
- Metadata is transformed with the first revertible
24+
transform in the list of `transforms`.
1625
"""
1726
struct ParallelTableTransform <: TableTransform
1827
transforms::Vector{Transform}
@@ -95,19 +104,16 @@ function revert(p::ParallelTableTransform, newtable, cache)
95104
fcols = Tables.columns(newfeat)
96105
names = Tables.columnnames(fcols)
97106

98-
# retrieve subtable to revert
107+
# subset of features to revert
99108
rnames = names[range]
100109
rcols = [Tables.getcolumn(fcols, j) for j in range]
101110
rfeat = (; zip(rnames, rcols)...) |> Tables.materializer(newfeat)
102111

103-
# revert transform on subtable
104-
feat = revert(rtrans, rfeat, rcache)
105-
106112
# propagate metadata
107-
meta = newmeta
113+
rtable = attach(rfeat, newmeta)
108114

109-
# attach features and metadata
110-
attach(feat, meta)
115+
# revert transform
116+
revert(rtrans, rtable, rcache)
111117
end
112118

113119
function reapply(p::ParallelTableTransform, table, cache)

test/metadata.jl

+31
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@
3232
mtₒ = revert(T, mn, mc)
3333
@test mtₒ.meta == mt.meta
3434
@test Tables.matrix(mtₒ.table) Tables.matrix(mt.table)
35+
36+
T = (Functional(sin) MinMax()) Center()
37+
mn, mc = apply(T, mt)
38+
tn, tc = apply(T, t)
39+
@test mn.meta == m
40+
@test mn.table == tn
41+
mtₒ = revert(T, mn, mc)
42+
@test mtₒ.meta == mt.meta
43+
@test Tables.matrix(mtₒ.table) Tables.matrix(mt.table)
3544
end
3645

3746
@testset "VarMeta" begin
@@ -67,5 +76,27 @@
6776
mtₒ = revert(T, mn, mc)
6877
@test mtₒ.meta == mt.meta
6978
@test Tables.matrix(mtₒ.table) Tables.matrix(mt.table)
79+
80+
# first revertible branch has two transforms,
81+
# so metadata is increased by 2 + 2 = 4
82+
T = (Functional(sin) MinMax()) Center()
83+
mn, mc = apply(T, mt)
84+
tn, tc = apply(T, t)
85+
@test mn.meta == VarMeta(m.data .+ 4)
86+
@test mn.table == tn
87+
mtₒ = revert(T, mn, mc)
88+
@test mtₒ.meta == mt.meta
89+
@test Tables.matrix(mtₒ.table) Tables.matrix(mt.table)
90+
91+
# first revertible branch has one transform,
92+
# so metadata is increased by 2
93+
T = Center() (Functional(sin) MinMax())
94+
mn, mc = apply(T, mt)
95+
tn, tc = apply(T, t)
96+
@test mn.meta == VarMeta(m.data .+ 2)
97+
@test mn.table == tn
98+
mtₒ = revert(T, mn, mc)
99+
@test mtₒ.meta == mt.meta
100+
@test Tables.matrix(mtₒ.table) Tables.matrix(mt.table)
70101
end
71102
end

0 commit comments

Comments
 (0)