diff --git a/src/transforms/map.jl b/src/transforms/map.jl index 1c9cff23..cc300ea9 100644 --- a/src/transforms/map.jl +++ b/src/transforms/map.jl @@ -55,7 +55,7 @@ struct Map <: StatelessFeatureTransform end function Map(args::MapArg...) - tups = map(_extract, args) + tups = map(_mapargs, args) sels = [t[1] for t in tups] funs = [t[2] for t in tups] tars = [t[3] for t in tups] @@ -85,10 +85,10 @@ function applyfeat(transform::Map, feat, prep) newfeat, nothing end -_extract(arg::ColsCallableTarget) = selector(first(arg)), first(last(arg)), Symbol(last(last(arg))) -_extract(arg::ColsCallable) = selector(first(arg)), last(arg), nothing -_extract(arg::CallableTarget) = AllSelector(), first(arg), Symbol(last(arg)) -_extract(arg::Callable) = AllSelector(), arg, nothing +_mapargs(arg::ColsCallableTarget) = selector(first(arg)), first(last(arg)), Symbol(last(last(arg))) +_mapargs(arg::ColsCallable) = selector(first(arg)), last(arg), nothing +_mapargs(arg::CallableTarget) = AllSelector(), first(arg), Symbol(last(arg)) +_mapargs(arg::Callable) = AllSelector(), arg, nothing function _makename(snames, fun) funname = _funname(fun) diff --git a/src/transforms/replace.jl b/src/transforms/replace.jl index 728065b1..c2007f24 100644 --- a/src/transforms/replace.jl +++ b/src/transforms/replace.jl @@ -44,14 +44,14 @@ end Replace() = throw(ArgumentError("cannot create Replace transform without arguments")) # utility functions -_extract(p::Pair) = AllSelector(), _pred(first(p)), last(p) -_extract(p::Pair{<:Any,<:Pair}) = selector(first(p)), _pred(first(last(p))), last(last(p)) +_replaceargs(p::Pair) = AllSelector(), _pred(first(p)), last(p) +_replaceargs(p::Pair{<:Any,<:Pair}) = selector(first(p)), _pred(first(last(p))), last(last(p)) _pred(f::Function) = f _pred(v) = Base.Fix2(===, v) function Replace(pairs::Pair...) - tuples = map(_extract, pairs) + tuples = map(_replaceargs, pairs) selectors = [t[1] for t in tuples] preds = [t[2] for t in tuples] news = Any[t[3] for t in tuples] diff --git a/test/transforms/replace.jl b/test/transforms/replace.jl index 26568ee0..78d81fc5 100644 --- a/test/transforms/replace.jl +++ b/test/transforms/replace.jl @@ -136,6 +136,12 @@ n, c = apply(T, rt) @test Tables.isrowtable(n) + # string replacement + t = Table(a=["A", "B", "C"]) + T = Replace("a" => ==("C") => "R") + n, c = apply(T, t) + @test n.a == ["A", "B", "R"] + # throws @test_throws ArgumentError Replace() end