Logical operators in julia

question
#1

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

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

#2

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

1 Like

#3

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

0 Likes

#4

& is the bitwise operator

prehaps you mean && which is the logical operator

0 Likes

#5

Try this:

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

#6

Thanks. It works.

0 Likes

#7

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

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

#8

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

2 Likes

#9

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