Skip to content

Commit

Permalink
Unitufy: Add support for non-numeric columns (#281)
Browse files Browse the repository at this point in the history
  • Loading branch information
eliascarv authored Jun 17, 2024
1 parent 27cad23 commit 1211dd5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/transforms/unitify.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function applyfeat(::Unitify, feat, prep)
pairs = map(names) do name
x = Tables.getcolumn(cols, name)
newname, unit = _unitify(name)
newname => x * unit
newname => _addunit(x, unit)
end

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

𝒯 = (; zip(onames, ocolumns)...)
Expand Down
11 changes: 11 additions & 0 deletions test/transforms/unitify.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,15 @@
@test unit(eltype(n.a)) === NoUnits
tₒ = revert(T, n, c)
@test tₒ == t

# non-numeric columns
t = Table(; anm => a, :b => rand('a':'z', 10), :c => categorical(rand(["yes", "no"], 10)))
T = Unitify()
n, c = apply(T, t)
@test Tables.schema(n).names == (:a, :b, :c)
@test unit(eltype(n.a)) === u"m"
@test eltype(n.b) <: Char
@test eltype(n.c) <: CategoricalValue
tₒ = revert(T, n, c)
@test tₒ == t
end

0 comments on commit 1211dd5

Please sign in to comment.