Skip to content

Commit 365f1a3

Browse files
committed
Adding a check within each_replacena to check if its a function and construct a EachReplaceNAWithFunctionResult
1 parent 89d517a commit 365f1a3

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

src/DataArrays.jl

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ module DataArrays
2525
each_failna,
2626
each_dropna,
2727
each_replacena,
28-
each_replacenawithfunctionresult,
2928
EachFailNA,
3029
EachDropNA,
3130
EachReplaceNA,

src/abstractdataarray.jl

+6-5
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,13 @@ type EachReplaceNA{S, T}
157157
replacement::T
158158
end
159159
function each_replacena(da::AbstractDataArray, replacement::Any)
160+
if isa(replacement, Function)
161+
EachReplaceNAWithFunctionResult(da, replacement)
162+
else
160163
EachReplaceNA(da, convert(eltype(da), replacement))
164+
end
161165
end
166+
162167
function each_replacena(replacement::Any)
163168
x -> each_replacena(x, replacement)
164169
end
@@ -172,15 +177,11 @@ end
172177
type EachReplaceNAWithFunctionResult{T}
173178
da::AbstractDataArray{T}
174179
f::Function
175-
withData::Bool
176-
end
177-
function each_replacenawithfunctionresult(da::AbstractDataArray, f::Function, withData::Bool)
178-
EachReplaceNAWithFunctionResult(da, f, withData)
179180
end
180181

181182
Base.start(itr::EachReplaceNAWithFunctionResult) = 1
182183
Base.done(itr::EachReplaceNAWithFunctionResult, ind::Int) = ind > length(itr.da)
183184
function Base.next(itr::EachReplaceNAWithFunctionResult, ind::Integer)
184-
item = isna(itr.da, ind) ? (itr.withData ? itr.f(itr.da) : itr.f()) : itr.da[ind]
185+
item = isna(itr.da, ind) ? itr.f(itr.da) : itr.da[ind]
185186
(item, ind + 1)
186187
end

test/nas.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,5 @@ module TestNAs
6767
dv = DataArray(Array(1:6), push!(fill(false, 3),fill(true, 3)...))
6868
a = dropna(dv)
6969
f = x -> round(Int, mean(dropna(x)))
70-
@test collect(each_replacenawithfunctionresult(dv, f, true)) == [1, 2, 3, 2, 2, 2]
70+
@test collect(each_replacena(dv, f)) == [1, 2, 3, 2, 2, 2]
7171
end

0 commit comments

Comments
 (0)