Skip to content

Commit 7b4264a

Browse files
authored
Add DropConstant transform (#252)
* Add 'DropConstant' transform * Apply suggestions
1 parent cc23cc7 commit 7b4264a

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

docs/src/transforms.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ DropExtrema
9292
DropUnits
9393
```
9494

95+
## DropConstant
96+
97+
```@docs
98+
DropConstant
99+
```
100+
95101
## AbsoluteUnits
96102

97103
```@docs

src/TableTransforms.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export
5454
Satisfies,
5555
Only,
5656
Except,
57+
DropConstant,
5758
Rename,
5859
StdNames,
5960
StdFeats,

src/transforms/satisfies.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,10 @@ Except(DST.Categorical)
6666
```
6767
"""
6868
Except(S::Type{<:SciType}) = Satisfies(x -> !(elscitype(x) <: S))
69+
70+
"""
71+
DropConstant()
72+
73+
Drops the constant columns using the `allequal` function.
74+
"""
75+
DropConstant() = Satisfies(!allequal)

test/transforms/satisfies.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,19 @@ end
7171
tₒ = revert(T, n, c)
7272
@test t == tₒ
7373
end
74+
75+
@testset "DropConstant" begin
76+
a = [4, 6, 7, 8, 1, 2]
77+
b = fill(5, 6)
78+
c = [1.9, 7.4, 8.6, 8.9, 2.4, 7.7]
79+
d = fill(5.5, 6)
80+
t = Table(; a, b, c, d)
81+
82+
T = DropConstant()
83+
n, c = apply(T, t)
84+
@test Tables.schema(n).names == (:a, :c)
85+
@test Tables.getcolumn(n, :a) == t.a
86+
@test Tables.getcolumn(n, :c) == t.c
87+
tₒ = revert(T, n, c)
88+
@test t == tₒ
89+
end

0 commit comments

Comments
 (0)