Skip to content

Commit cc1a26d

Browse files
authored
Fix Replace arguments (#320)
1 parent 968d193 commit cc1a26d

3 files changed

Lines changed: 14 additions & 8 deletions

File tree

src/transforms/map.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ struct Map <: StatelessFeatureTransform
5555
end
5656

5757
function Map(args::MapArg...)
58-
tups = map(_extract, args)
58+
tups = map(_mapargs, args)
5959
sels = [t[1] for t in tups]
6060
funs = [t[2] for t in tups]
6161
tars = [t[3] for t in tups]
@@ -85,10 +85,10 @@ function applyfeat(transform::Map, feat, prep)
8585
newfeat, nothing
8686
end
8787

88-
_extract(arg::ColsCallableTarget) = selector(first(arg)), first(last(arg)), Symbol(last(last(arg)))
89-
_extract(arg::ColsCallable) = selector(first(arg)), last(arg), nothing
90-
_extract(arg::CallableTarget) = AllSelector(), first(arg), Symbol(last(arg))
91-
_extract(arg::Callable) = AllSelector(), arg, nothing
88+
_mapargs(arg::ColsCallableTarget) = selector(first(arg)), first(last(arg)), Symbol(last(last(arg)))
89+
_mapargs(arg::ColsCallable) = selector(first(arg)), last(arg), nothing
90+
_mapargs(arg::CallableTarget) = AllSelector(), first(arg), Symbol(last(arg))
91+
_mapargs(arg::Callable) = AllSelector(), arg, nothing
9292

9393
function _makename(snames, fun)
9494
funname = _funname(fun)

src/transforms/replace.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ end
4444
Replace() = throw(ArgumentError("cannot create Replace transform without arguments"))
4545

4646
# utility functions
47-
_extract(p::Pair) = AllSelector(), _pred(first(p)), last(p)
48-
_extract(p::Pair{<:Any,<:Pair}) = selector(first(p)), _pred(first(last(p))), last(last(p))
47+
_replaceargs(p::Pair) = AllSelector(), _pred(first(p)), last(p)
48+
_replaceargs(p::Pair{<:Any,<:Pair}) = selector(first(p)), _pred(first(last(p))), last(last(p))
4949

5050
_pred(f::Function) = f
5151
_pred(v) = Base.Fix2(===, v)
5252

5353
function Replace(pairs::Pair...)
54-
tuples = map(_extract, pairs)
54+
tuples = map(_replaceargs, pairs)
5555
selectors = [t[1] for t in tuples]
5656
preds = [t[2] for t in tuples]
5757
news = Any[t[3] for t in tuples]

test/transforms/replace.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@
136136
n, c = apply(T, rt)
137137
@test Tables.isrowtable(n)
138138

139+
# string replacement
140+
t = Table(a=["A", "B", "C"])
141+
T = Replace("a" => ==("C") => "R")
142+
n, c = apply(T, t)
143+
@test n.a == ["A", "B", "R"]
144+
139145
# throws
140146
@test_throws ArgumentError Replace()
141147
end

0 commit comments

Comments
 (0)