Logical operators in julia

Why the code below does not work in julia 1.0.3? it used to work earlier.

data_full[(data_full[:is_minor] .== 1 ) & (data_full[:LA_INC] .<= 0),:]

MethodError: no method matching &(::BitArray{1}, ::BitArray{1})
Closest candidates are:
  &(::Any, ::Any, !Matched::Any, !Matched::Any...) at operators.jl:502

 [1] top-level scope at In[21]:3

Without knowing what you expected as the output, I think you want to broadcast the & as well.


I am trying to filter records based on the two conditions.

& is the bitwise operator

prehaps you mean && which is the logical operator

Try this:

data_full[(data_full[:is_minor] .== 1 ) .& (data_full[:LA_INC] .<= 0),:]
1 Like

Thanks. It works.

You should broadcast the & as well , note there’s a . before &

data_full[(data_full[:is_minor] .== 1 ) .& (data_full[:LA_INC] .<= 0),:]

Are you updating from Julia 0.5 to 1.0? If so, it might make sense to go in steps via 0.6 and 0.7 as those will give you deprecation warnings and tell you how to upgrade your code; or at least when you hit raod-blocks. In Julia 0.6 this gave:

julia> trues(2) & trues(2)
WARNING: A::AbstractArray & B::AbstractArray is deprecated, use A .& B instead.

See also PSA: use Julia 0.7 if you are upgrading


It sounds like a pain but I think it will be easier overall. Each set of deprecations is pretty easy by itself, 0.6 => 0.7/1.0 is the hardest since it has the most deprecations.

1 Like