Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reduce(max, ::Vector{Missing}) only works for certain lengths #30816

Closed
cstjean opened this issue Jan 23, 2019 · 3 comments
Closed

reduce(max, ::Vector{Missing}) only works for certain lengths #30816

cstjean opened this issue Jan 23, 2019 · 3 comments
Labels
bug Indicates an unexpected problem or unintended behavior missing data Base.missing and related functionality

Comments

@cstjean
Copy link
Contributor

cstjean commented Jan 23, 2019

In julia 1.0.3,

julia> reduce(max, fill(missing, 15))    # good
missing

julia> reduce(max, fill(missing, 16))
ERROR: TypeError: non-boolean (Missing) used in boolean context
Stacktrace:
 [1] mapreduce_impl at ./reduce.jl:460 [inlined]
 [2] _mapreduce(::typeof(identity), ::typeof(max), ::IndexLinear, ::Array{Missing,1}) at ./reduce.jl:318
 [3] _mapreduce_dim(::Function, ::Function, ::NamedTuple{(),Tuple{}}, ::Array{Missing,1}, ::Colon) at ./reducedim.jl:305
 [4] #mapreduce#536 at ./reducedim.jl:301 [inlined]
 [5] mapreduce at ./reducedim.jl:301 [inlined]
 [6] #reduce#537 at ./reducedim.jl:345 [inlined]
 [7] reduce(::Function, ::Array{Missing,1}) at ./reducedim.jl:345
 [8] top-level scope at none:0

julia> reduce((a,b)->max(a,b), fill(missing, 16))
missing
@nalimilan
Copy link
Member

On master:

julia> reduce(max, fill(missing, 16))
missing

Unfortunately, it's not fixed on 1.1. Maybe the fix can be backported though (if we can identify it).

@nalimilan nalimilan added bug Indicates an unexpected problem or unintended behavior missing data Base.missing and related functionality labels Jan 23, 2019
@nalimilan
Copy link
Member

Wait, the threshold has just increased to 257:

julia> reduce(max, fill(missing, 257))
ERROR: TypeError: non-boolean (Missing) used in boolean context
Stacktrace:
 [1] mapreduce_impl(::typeof(identity), ::typeof(max), ::Array{Missing,1}, ::Int64, ::Int64) at ./reduce.jl:485
 [2] _mapreduce(::typeof(identity), ::typeof(max), ::IndexLinear, ::Array{Missing,1}) at ./reduce.jl:320
 [3] _mapreduce_dim(::Function, ::Function, ::NamedTuple{(),Tuple{}}, ::Array{Missing,1}, ::Colon) at ./reducedim.jl:308
 [4] #mapreduce#543 at ./reducedim.jl:304 [inlined]
 [5] mapreduce at ./reducedim.jl:304 [inlined]
 [6] #reduce#544 at ./reducedim.jl:348 [inlined]
 [7] reduce(::Function, ::Array{Missing,1}) at ./reducedim.jl:348
 [8] top-level scope at REPL[11]:1

A more direct reproducer is Base.mapreduce_impl(identity, max, fill(missing, 257), 1, 257). We just need to replace v == v in that function with something like (ismissing(v) || v == v) or (v == v) !== false. Or it could be clearer to move that condition inside the loop and write !ismissing(v) && v != v && continue.

@KristofferC
Copy link
Member

#35989

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior missing data Base.missing and related functionality
Projects
None yet
Development

No branches or pull requests

3 participants