diff --git a/src/reduce.jl b/src/reduce.jl index 015db0f..5396a2b 100644 --- a/src/reduce.jl +++ b/src/reduce.jl @@ -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 @@ -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 diff --git a/test/reduce.jl b/test/reduce.jl index a30384b..e73133f 100644 --- a/test/reduce.jl +++ b/test/reduce.jl @@ -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...)