Skip to content
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

Merged
merged 13 commits into from
Sep 22, 2021
Merged

Conversation

bkamins
Copy link
Member

@bkamins bkamins commented Sep 7, 2021

This addresses issues discussed in #42065 (comment) for deleteat!.

base/array.jl Outdated Show resolved Hide resolved
@bkamins
Copy link
Member Author

bkamins commented Sep 7, 2021

What problems this PR tries to solve:

julia> deleteat!([1, 2, 3], true)
2-element Vector{Int64}:
 2
 3

julia> deleteat!([1, 2, 3], true:true)
2-element Vector{Int64}:
 2
 3

julia> deleteat!(trues(3), [true, false, false])
ERROR: ArgumentError: indices must be unique and sorted

julia> deleteat!(trues(3), [UInt8(1)])
ERROR: MethodError: no method matching copy_chunks!(::Vector{UInt64}, ::UInt8, ::Vector{UInt64}, ::Int64, ::Int64)

base/array.jl Outdated Show resolved Hide resolved
@bkamins bkamins marked this pull request as ready for review September 7, 2021 13:36
@bkamins
Copy link
Member Author

bkamins commented Sep 7, 2021

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))
Copy link
Member Author

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?

Copy link
Member

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!.

Copy link
Member Author

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.

Copy link
Member

@dkarrasch dkarrasch left a 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.

base/array.jl Outdated Show resolved Hide resolved
base/array.jl Outdated Show resolved Hide resolved
base/bitarray.jl Outdated Show resolved Hide resolved
base/bitarray.jl Outdated Show resolved Hide resolved
base/array.jl Outdated Show resolved Hide resolved
@bkamins
Copy link
Member Author

bkamins commented Sep 16, 2021

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!

@nalimilan
Copy link
Member

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.

@JeffBezanson
Copy link
Member

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"))
Copy link
Member Author

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
Copy link
Member Author

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

@bkamins
Copy link
Member Author

bkamins commented Sep 18, 2021

just need to fix the tests.

I have fixed. Actually the test was correct, but it was failing because there was an additional issue with lacking conversion to Int in the old code that required fixing. Now it should be good for a review. I have added some comments in places that are non-obvious without running the code.

@bkamins bkamins closed this Sep 18, 2021
@bkamins bkamins reopened this Sep 18, 2021
@bkamins
Copy link
Member Author

bkamins commented Sep 18, 2021

re-triggering CI

@bkamins
Copy link
Member Author

bkamins commented Sep 18, 2021

A single CI error seems unrelated, so this should be good for a final review.

base/array.jl Outdated Show resolved Hide resolved
base/array.jl Outdated Show resolved Hide resolved
base/bitarray.jl Outdated Show resolved Hide resolved
base/bitarray.jl Outdated Show resolved Hide resolved
base/bitarray.jl Outdated Show resolved Hide resolved
@JeffBezanson JeffBezanson added backport 1.7 merge me PR is reviewed. Merge when all tests are passing labels Sep 21, 2021
@JeffBezanson JeffBezanson reopened this Sep 22, 2021
@JeffBezanson JeffBezanson merged commit deb3fac into JuliaLang:master Sep 22, 2021
@bkamins bkamins deleted the patch-29 branch September 22, 2021 19:16
@DilumAluthge DilumAluthge removed the merge me PR is reviewed. Merge when all tests are passing label Sep 24, 2021
KristofferC pushed a commit that referenced this pull request Sep 28, 2021
KristofferC pushed a commit that referenced this pull request Oct 5, 2021
Co-authored-by: Daniel Karrasch <[email protected]>
(cherry picked from commit deb3fac)
LilithHafner pushed a commit to LilithHafner/julia that referenced this pull request Feb 22, 2022
LilithHafner pushed a commit to LilithHafner/julia that referenced this pull request Mar 8, 2022
@bkamins
Copy link
Member Author

bkamins commented Mar 13, 2023

Could this PR be backported to 1.6 release? see JuliaData/DataFrames.jl#3300

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants