Closed gergelyattilakiss closed 5 days ago
constant conditions are a bit more difficult, they are expressions, but in the bitmask they are evaluated as booleans that can not be row condition.
fixed in 0bf74c7d3e457fe74aec30aabbf0c7c49dbbb918 , used variables do not make a problem because @if
only looks for variabels in the dataframe, and later if we add context with scalars(...)
, then in scalars
too.
Now I see the problem. If the condition returns a vector, we get a BitVector that can be used to index the dataframe.
If the condition is a scalar, it cannot be used for indexing.
What if we just add a vector of 0s? Automatic broadcasting should turn the scalar into a vector, and we are fine.
BitVector(zeros(Bool, n)) .| bitmask
Will start working on it.
No, that's the beauty. Broadcasting is automatic and false | x is equal to x. The only difference is that BitVector .| x will be Vector shaped.
julia> BitVector(zeros(5)) .| false
5-element BitVector:
0
0
0
0
0
julia> BitVector(zeros(5)) .| true
5-element BitVector:
1
1
1
1
1
julia> BitVector(zeros(5)) .| [1, 0, 1, 1, 0]
5-element Vector{Int64}:
1
0
1
1
0
Yepp, I started testing these in terminal and see how it goes.
Make sure to put $bitmask in () to ensure operator precedence.
Do we prefer inline solution or should I put the indexing vector into a different variable?
It took me sometime to find the proper place for the broadcasting... but it seems to work fine now.
I'd rather add this to build_bitmask
Please move to build_bitmask
. This will be easier to maintain and to merge with other code.
Also add at least 3 tests for this condition, like if true
and if 2 + 2 == 4
and if 1 < 0
Constant conditions are not working well