Skip to content

Commit

Permalink
fix delete! for versions of Julia 1.6.2 or earlier (#2820)
Browse files Browse the repository at this point in the history
  • Loading branch information
bkamins authored Jul 20, 2021
1 parent ab5ffd7 commit fca65fe
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# DataFrames.jl v1.2.1 Patch Release Notes

## Bug fixes

* Add workaround for `deleteat!` bug in Julia Base in `delete!` function
([#2820](https://github.com/JuliaData/DataFrames.jl/issues/2820))

# DataFrames.jl v1.2 Release Notes

## New functionalities
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "DataFrames"
uuid = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
version = "1.2.0"
version = "1.2.1"

[deps]
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
Expand Down
9 changes: 9 additions & 0 deletions src/dataframe/dataframe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,11 @@ function Base.delete!(df::DataFrame, inds)
throw(BoundsError(df, (inds, :)))
end

# workaround https://github.com/JuliaLang/julia/pull/41646
if VERSION <= v"1.6.2" && inds isa UnitRange{<:Integer}
inds = collect(inds)
end

# we require ind to be stored and unique like in Base
# otherwise an error will be thrown and the data frame will get corrupted
return _delete!_helper(df, inds)
Expand All @@ -976,6 +981,10 @@ function Base.delete!(df::DataFrame, inds::AbstractVector{Bool})
throw(BoundsError(df, (inds, :)))
end
drop = _findall(inds)
# workaround https://github.com/JuliaLang/julia/pull/41646
if VERSION <= v"1.6.2" && drop isa UnitRange{<:Integer}
drop = collect(drop)
end
return _delete!_helper(df, drop)
end

Expand Down
13 changes: 12 additions & 1 deletion test/data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ end
:auto)
df2 = DataFrame([Union{Int, Missing}[1, 2, 3, 4], ["one", "two", missing, "four"]],
:auto)
df3 = DataFrame(x = Int[1, 2, 3, 4], y = Union{Int, Missing}[1, missing, 2, 3],
df3 = DataFrame(x = Int[1, 2, 3, 4], y = Union{Int, Missing}[1, missing, 2, 3],
z = Missing[missing, missing, missing, missing])

@test completecases(df2) == .!ismissing.(df2.x2)
Expand Down Expand Up @@ -192,6 +192,17 @@ end
@test eltype(dropmissing!(df).b) == Int
end

@testset "delete! https://github.com/JuliaLang/julia/pull/41646 bug workaround" begin
# these tests will crash Julia if they are not correct
df = DataFrame(a= Vector{Union{Bool,Missing}}(missing, 10^4));
delete!(df, 2:(nrow(df) - 5))
@test nrow(df) == 6

df = DataFrame(a= Vector{Union{Bool,Missing}}(missing, 10^4));
delete!(df, [false; trues(nrow(df) - 6); falses(5)])
@test nrow(df) == 6
end

@testset "dropmissing and unique view kwarg test" begin
df = DataFrame(rand(3, 4), :auto)
for fun in (dropmissing, unique)
Expand Down

2 comments on commit fca65fe

@bkamins
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/41228

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.2.1 -m "<description of version>" fca65fec0b30b3b7869a2323a67bbda8272b90a3
git push origin v1.2.1

Please sign in to comment.