Skip to content

Commit b493040

Browse files
committed
Group utilities in utils.jl
1 parent d8e945e commit b493040

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

src/TableTransforms.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import Distributions: quantile, cdf
3232
import TransformsBase: assertions, parameters, isrevertible, isinvertible
3333
import TransformsBase: apply, revert, reapply, preprocess, inverse
3434

35+
include("utils.jl")
3536
include("tabletraits.jl")
3637
include("distributions.jl")
3738
include("tableselection.jl")

src/transforms/dropunits.jl

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@ DropUnits(cols::C...) where {C<:Column} = DropUnits(selector(cols))
3838

3939
isrevertible(::Type{<:DropUnits}) = true
4040

41-
_dropunit(x) = _dropunit(x, nonmissingtype(eltype(x)))
42-
_dropunit(x, ::Type{Q}) where {Q<:AbstractQuantity} = (map(ustrip, x), unit(Q))
43-
_dropunit(x, ::Type) = (x, NoUnits)
44-
4541
function applyfeat(transform::DropUnits, feat, prep)
4642
cols = Tables.columns(feat)
4743
names = Tables.columnnames(cols)
@@ -60,17 +56,14 @@ function applyfeat(transform::DropUnits, feat, prep)
6056
newfeat, (snames, units)
6157
end
6258

63-
_addunit(x, ::typeof(NoUnits)) = x
64-
_addunit(x, u::Units) = map(v -> v * u, x)
65-
6659
function revertfeat(::DropUnits, newfeat, fcache)
6760
cols = Tables.columns(newfeat)
6861
names = Tables.columnnames(cols)
6962

7063
snames, units = fcache
7164
columns = map(names, units) do name, unit
7265
x = Tables.getcolumn(cols, name)
73-
name snames ? _addunit(x, unit) : x
66+
name snames ? _withunit(x, unit) : x
7467
end
7568

7669
𝒯 = (; zip(names, columns)...)

src/transforms/unitify.jl

Lines changed: 1 addition & 1 deletion
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 => _addunit(x, unit)
48+
newname => _withunit(x, unit)
4949
end
5050

5151
newfeat = (; pairs...) |> Tables.materializer(feat)

src/utils.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# ------------------------------------------------------------------
2+
# Licensed under the MIT License. See LICENSE in the project root.
3+
# ------------------------------------------------------------------
4+
5+
_dropunit(x) = _dropunit(x, nonmissingtype(eltype(x)))
6+
_dropunit(x, ::Type{Q}) where {Q<:AbstractQuantity} = (map(ustrip, x), unit(Q))
7+
_dropunit(x, ::Type) = (x, NoUnits)
8+
9+
_withunit(x, ::typeof(NoUnits)) = x
10+
_withunit(x, u::Units) = map(v -> v * u, x)

0 commit comments

Comments
 (0)