Boolean indexing deprecated?

question
deprecation

#1

From the NEWS.md file:

Using Bool values directly as indices is now deprecated and will be an error in the future. Convert them to Int before indexing if you intend to access index 1 for true and 0 for false.

Does that mean that we won’t be able to mask arrays with boolean masks anymore? That sounds terrible, can someone please clarify this?


#2
julia> a = [1,2]
2-element Array{Int64,1}:
 1
 2

julia> a[[false, true]]
1-element Array{Int64,1}:
 2

julia> a[true]
WARNING: indexing with Bool values is deprecated. Convert the index to an integer first with `Int(i)`.
Stacktrace:
 [1] depwarn(::String, ::Tuple{Symbol,Symbol,Symbol}) at ./deprecated.jl:68
 [2] to_index at ./deprecated.jl:1854 [inlined]
 [3] to_index at ./indices.jl:173 [inlined]
 [4] to_indices at ./indices.jl:218 [inlined]
 [5] to_indices at ./multidimensional.jl:512 [inlined]
 [6] getindex(::Array{Int64,1}, ::Bool) at ./multidimensional.jl:372
 [7] top-level scope
 [8] eval(::Module, ::Expr) at ./repl/REPL.jl:3
 [9] eval_user_input(::Any, ::Base.REPL.REPLBackend) at ./repl/REPL.jl:69
 [10] macro expansion at ./repl/REPL.jl:100 [inlined]
 [11] (::getfield(Base.REPL, Symbol("##1#2")){Base.REPL.REPLBackend})() at ./event.jl:95
in expression starting at no file:0
1

julia> a[false]
ERROR: BoundsError: attempt to access 2-element Array{Int64,1} at index [0]
Stacktrace:
 [1] getindex(::Array{Int64,1}, ::Bool) at ./multidimensional.jl:372
 [2] top-level scope

#3

Thank you @Keno for clarifying the note in the NEWS, I was about to have a mental crisis :slight_smile:


#4

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.