Repository: JuliaML/TableTransforms.jl (julia)

Issue:
Add `DropConstant` transform to drop constant columns
Constant columns can be dropped in many statistical procedures (e.g. PCA).

Pull request description:
closes #251

Patch:
diff --git a/docs/src/transforms.md b/docs/src/transforms.md
index 912a055f..0c1499b8 100644
--- a/docs/src/transforms.md
+++ b/docs/src/transforms.md
@@ -92,6 +92,12 @@ DropExtrema
 DropUnits
 ```
 
+## DropConstant
+
+```@docs
+DropConstant
+```
+
 ## AbsoluteUnits
 
 ```@docs
diff --git a/src/TableTransforms.jl b/src/TableTransforms.jl
index a2dabbc7..7b557ffa 100644
--- a/src/TableTransforms.jl
+++ b/src/TableTransforms.jl
@@ -54,6 +54,7 @@ export
   Satisfies,
   Only,
   Except,
+  DropConstant,
   Rename,
   StdNames,
   StdFeats,
diff --git a/src/transforms/satisfies.jl b/src/transforms/satisfies.jl
index ba7b8791..27aeefac 100644
--- a/src/transforms/satisfies.jl
+++ b/src/transforms/satisfies.jl
@@ -66,3 +66,10 @@ Except(DST.Categorical)
 ```
 """
 Except(S::Type{<:SciType}) = Satisfies(x -> !(elscitype(x) <: S))
+
+"""
+    DropConstant()
+
+Drops the constant columns using the `allequal` function.
+"""
+DropConstant() = Satisfies(!allequal)


Test patch:
diff --git a/test/transforms/satisfies.jl b/test/transforms/satisfies.jl
index ef077634..4af20004 100644
--- a/test/transforms/satisfies.jl
+++ b/test/transforms/satisfies.jl
@@ -71,3 +71,19 @@ end
   tₒ = revert(T, n, c)
   @test t == tₒ
 end
+
+@testset "DropConstant" begin
+  a = [4, 6, 7, 8, 1, 2]
+  b = fill(5, 6)
+  c = [1.9, 7.4, 8.6, 8.9, 2.4, 7.7]
+  d = fill(5.5, 6)
+  t = Table(; a, b, c, d)
+
+  T = DropConstant()
+  n, c = apply(T, t)
+  @test Tables.schema(n).names == (:a, :c)
+  @test Tables.getcolumn(n, :a) == t.a
+  @test Tables.getcolumn(n, :c) == t.c
+  tₒ = revert(T, n, c)
+  @test t == tₒ
+end