Skip to content

Commit e467f45

Browse files
authored
Add missing support to StdFeats transform (#307)
1 parent ffd68f3 commit e467f45

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/transforms/stdfeats.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ isrevertible(::Type{StdFeats}) = true
1818
_stdfun(x) = _stdfun(elscitype(x), x)
1919
_stdfun(::Type, x) = identity, identity
2020
function _stdfun(::Type{Continuous}, x)
21-
μ = mean(x)
22-
σ = std(x, mean=μ)
21+
μ = mean(skipmissing(x))
22+
σ = std(skipmissing(x), mean=μ)
2323
stdfun = x -> zscore(x, μ, σ)
2424
revfun = y -> revzscore(y, μ, σ)
2525
stdfun, revfun

test/transforms/stdfeats.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,14 @@
2323
@test tₒ.c == t.c
2424
@test tₒ.d t.d
2525
@test tₒ.e == t.e
26+
27+
# missing values
28+
a = [rand(1:10, 99); missing]
29+
b = [rand(Normal(7, 10), 99); missing]
30+
t = Table(; a, b)
31+
T = StdFeats()
32+
n, c = apply(T, t)
33+
@test isequal(n.a, t.a)
34+
@test isapprox(mean(skipmissing(n.b)), 0; atol=1e-6)
35+
@test isapprox(std(skipmissing(n.b)), 1; atol=1e-6)
2636
end

0 commit comments

Comments
 (0)