Skip to content

Commit

Permalink
Rename variables
Browse files Browse the repository at this point in the history
  • Loading branch information
eliascarv committed Nov 14, 2023
1 parent cb998f6 commit 13e8869
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions src/transforms/select.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,17 @@ _newnames(::Nothing, select) = select
_newnames(names::Vector{Symbol}, select) = names

function applyfeat(transform::Select, feat, prep)
# original columns
cols = Tables.columns(feat)
names = collect(Tables.columnnames(cols))

# retrieve relevant column names
allcols = collect(Tables.columnnames(cols))
select = transform.selector(allcols)
names = _newnames(transform.newnames, select)
reject = setdiff(allcols, select)
select = transform.selector(names)
reject = setdiff(names, select)
newnames = _newnames(transform.newnames, select)

# keep track of indices to revert later
sinds = indexin(select, allcols)
rinds = indexin(reject, allcols)
sinds = indexin(select, names)
rinds = indexin(reject, names)

# sort indices to facilitate reinsertion
sperm = sortperm(sinds)
Expand All @@ -72,18 +71,16 @@ function applyfeat(transform::Select, feat, prep)
rcolumns = [Tables.getcolumn(cols, name) for name in reject]

fcache = (select, sperm, reject, rcolumns, rinds)
newfeat = TableSelection(feat, names, select)
newfeat = TableSelection(feat, newnames, select)
newfeat, fcache
end

function revertfeat(::Select, newfeat, fcache)
# selected columns
cols = Tables.columns(newfeat)
names = Tables.columnnames(cols)
# https://github.com/JuliaML/TableTransforms.jl/issues/76
columns = Any[Tables.getcolumn(cols, name) for name in names]

# rejected columns
select, sperm, reject, rcolumns, rinds = fcache

# restore rejected columns
Expand Down Expand Up @@ -136,9 +133,9 @@ isrevertible(::Type{<:Reject}) = true

function applyfeat(transform::Reject, feat, prep)
cols = Tables.columns(feat)
allcols = Tables.columnnames(cols)
reject = transform.selector(allcols)
select = setdiff(allcols, reject)
names = Tables.columnnames(cols)
reject = transform.selector(names)
select = setdiff(names, reject)
strans = Select(select)
newfeat, sfcache = applyfeat(strans, feat, prep)
newfeat, (strans, sfcache)
Expand Down

0 comments on commit 13e8869

Please sign in to comment.