-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Improve corner cases of deleteat! #42144
Conversation
What problems this PR tries to solve:
|
I will add tests and NEWS.md entry if the proposed changes would be acceptable. |
base/bitarray.jl
Outdated
if length(B) != length(inds) | ||
throw(ArgumentError("length of Bool indices inds must match the length of B")) | ||
end | ||
return deleteat!(B, findall(inds)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clearly this can be made faster, but will lead to some code duplication. Should I improve things here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems fine for now. Would it be faster to reuse the code for Vector (at least avoiding the allocation)? The Vector method should work if _deleteend!
is just replaced with resize!
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no - it would not be fully efficient. I will implement an efficient method and you will judge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just stumbled across the typo.
Co-authored-by: Daniel Karrasch <[email protected]>
Co-authored-by: Jeff Bezanson <[email protected]>
I have not made PRs to Julia for some time. Could someone please guide me through which CI jobs are running the actual tests of the functionality? (as there seem to be many jobs doing some specific testing) Thank you! |
AFAIK "package" jobs only build Julia, "tester" jobs run the tests. Not sure about others. |
Looks great, just need to fix the tests. |
@@ -987,25 +988,68 @@ function deleteat!(B::BitVector, inds) | |||
|
|||
(p, s) = y | |||
checkbounds(B, p) | |||
p isa Bool && throw(ArgumentError("invalid index $p of type Bool")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can throw an error here (and not just warn about deprecation), because earlier it already threw an error as a side effect of lack of conversion of p
to Int
where needed later. (same below)
The current behavior is:
julia> deleteat!(falses(5), Any[true])
ERROR: MethodError: no method matching copy_chunks!(::Vector{UInt64}, ::Bool, ::Vector{UInt64}, ::Int64, ::Int64)
julia> deleteat!(falses(5), Any[1, true])
ERROR: ArgumentError: indices must be unique and sorted
Now in both cases we will throw throw(ArgumentError("invalid index $p of type Bool"))
@@ -1020,6 +1064,10 @@ function deleteat!(B::BitVector, inds) | |||
end | |||
|
|||
function splice!(B::BitVector, i::Integer) | |||
# TODO: after deprecation remove the four lines below |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have also added the checks for Bool
to splice!
as they are done in non-BitVector
case:
julia> splice!([1,2,3], true)
ERROR: ArgumentError: invalid index: true of type Bool
julia> splice!([1,2,3], true, [4,5])
ERROR: ArgumentError: invalid index: true of type Bool
I have fixed. Actually the test was correct, but it was failing because there was an additional issue with lacking conversion to |
re-triggering CI |
A single CI error seems unrelated, so this should be good for a final review. |
Co-authored-by: Daniel Karrasch <[email protected]>
Co-authored-by: Daniel Karrasch <[email protected]> (cherry picked from commit deb3fac)
Co-authored-by: Daniel Karrasch <[email protected]>
Co-authored-by: Daniel Karrasch <[email protected]>
Could this PR be backported to 1.6 release? see JuliaData/DataFrames.jl#3300 |
This addresses issues discussed in #42065 (comment) for
deleteat!
.