Skip to content
This repository was archived by the owner on May 4, 2019. It is now read-only.

Fix mapreduce() in a corner case #281

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/reduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ function mapreduce_seq_impl_skipna(f, op, T, A::DataArray, ifirst::Int, ilast::I

while i < ilast
i += 1
@inbounds na = Base.unsafe_bitgetindex(chunks, i)
na && continue
@inbounds na_el = Base.unsafe_bitgetindex(chunks, i)
na_el && continue
@inbounds d = data[i]
v = op(v, f(d))
end
Expand All @@ -36,7 +36,7 @@ function mapreduce_pairwise_impl_skipna{T}(f, op, A::DataArray{T}, bytefirst::In
ifirst = 64*(bytefirst-1)+1
ilast = min(64*bytelast, length(A))
# Fall back to Base implementation if no NAs in block
return ilast - ifirst + 1 == n_notna ? Base.mapreduce_seq_impl(f, op, A.data, ifirst, ilast) :
return ilast - ifirst + 1 == n_notna ? Base.mapreduce_impl(f, op, A.data, ifirst, ilast) :
mapreduce_seq_impl_skipna(f, op, T, A, ifirst, ilast)
end

Expand Down
6 changes: 6 additions & 0 deletions test/reduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ end
@test sum(da2; skipna=true) ≈ sum(dropna(da2))
end

# Check that mapreduce with skipna=true works when a full block has no NA
da = DataArray(1:2049)
da[1] = NA
@test isna(sum(da))
@test sum(da, skipna=true) === 2100224

## other reductions

_varuc(x; kw...) = var(x; corrected=false, kw...)
Expand Down