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

fix delete! for versions of Julia 1.6.2 or earlier #2820

Merged
merged 2 commits into from
Jul 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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