Skip to content

Commit 1211dd5

Browse files
authored
Unitufy: Add support for non-numeric columns (#281)
1 parent 27cad23 commit 1211dd5

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/transforms/unitify.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function applyfeat(::Unitify, feat, prep)
4545
pairs = map(names) do name
4646
x = Tables.getcolumn(cols, name)
4747
newname, unit = _unitify(name)
48-
newname => x * unit
48+
newname => _addunit(x, unit)
4949
end
5050

5151
newfeat = (; pairs...) |> Tables.materializer(feat)
@@ -59,7 +59,7 @@ function revertfeat(::Unitify, newfeat, fcache)
5959
onames = fcache
6060
ocolumns = map(names) do name
6161
x = Tables.getcolumn(cols, name)
62-
ustrip.(x)
62+
first(_dropunit(x))
6363
end
6464

6565
𝒯 = (; zip(onames, ocolumns)...)

test/transforms/unitify.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,15 @@
4242
@test unit(eltype(n.a)) === NoUnits
4343
tₒ = revert(T, n, c)
4444
@test tₒ == t
45+
46+
# non-numeric columns
47+
t = Table(; anm => a, :b => rand('a':'z', 10), :c => categorical(rand(["yes", "no"], 10)))
48+
T = Unitify()
49+
n, c = apply(T, t)
50+
@test Tables.schema(n).names == (:a, :b, :c)
51+
@test unit(eltype(n.a)) === u"m"
52+
@test eltype(n.b) <: Char
53+
@test eltype(n.c) <: CategoricalValue
54+
tₒ = revert(T, n, c)
55+
@test tₒ == t
4556
end

0 commit comments

Comments
 (0)