Repository: JuliaML/TableTransforms.jl (julia)

Issue:
Add support for `missing`  values in `StdFeats` transform
The transform currently fails with `missing` values.

Pull request description:
Fix https://github.com/JuliaEarth/GeoStats.jl/issues/555

Patch:
diff --git a/src/transforms/stdfeats.jl b/src/transforms/stdfeats.jl
index 319adca6..31397494 100644
--- a/src/transforms/stdfeats.jl
+++ b/src/transforms/stdfeats.jl
@@ -18,8 +18,8 @@ isrevertible(::Type{StdFeats}) = true
 _stdfun(x) = _stdfun(elscitype(x), x)
 _stdfun(::Type, x) = identity, identity
 function _stdfun(::Type{Continuous}, x)
-  μ = mean(x)
-  σ = std(x, mean=μ)
+  μ = mean(skipmissing(x))
+  σ = std(skipmissing(x), mean=μ)
   stdfun = x -> zscore(x, μ, σ)
   revfun = y -> revzscore(y, μ, σ)
   stdfun, revfun


Test patch:
diff --git a/test/transforms/stdfeats.jl b/test/transforms/stdfeats.jl
index e60df22b..feb23d7f 100644
--- a/test/transforms/stdfeats.jl
+++ b/test/transforms/stdfeats.jl
@@ -23,4 +23,14 @@
   @test tₒ.c == t.c
   @test tₒ.d ≈ t.d
   @test tₒ.e == t.e
+
+  # missing values
+  a = [rand(1:10, 99); missing]
+  b = [rand(Normal(7, 10), 99); missing]
+  t = Table(; a, b)
+  T = StdFeats()
+  n, c = apply(T, t)
+  @test isequal(n.a, t.a)
+  @test isapprox(mean(skipmissing(n.b)), 0; atol=1e-6)
+  @test isapprox(std(skipmissing(n.b)), 1; atol=1e-6)
 end