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

[BREAKING] Rename deleterows! to delete! #2189

Merged
merged 1 commit into from
Apr 15, 2020
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
2 changes: 1 addition & 1 deletion docs/src/lib/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ categorical!
completecases
copy
DataFrame!
deleterows!
delete!
describe
disallowmissing
disallowmissing!
Expand Down
1 change: 0 additions & 1 deletion src/DataFrames.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export AbstractDataFrame,
combine,
completecases,
crossjoin,
deleterows!,
describe,
disallowmissing!,
dropmissing!,
Expand Down
12 changes: 6 additions & 6 deletions src/abstractdataframe/abstractdataframe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,7 @@ julia> dropmissing!(df3, [:x, :y])
function dropmissing!(df::AbstractDataFrame,
cols::Union{ColumnIndex, AbstractVector, Regex, Not, Between, All, Colon}=:;
disallowmissing::Bool=true)
deleterows!(df, (!).(completecases(df, cols)))
delete!(df, (!).(completecases(df, cols)))
disallowmissing && disallowmissing!(df, cols)
df
end
Expand Down Expand Up @@ -1054,7 +1054,7 @@ function _filter!_helper(df::AbstractDataFrame, f, cols...)
if length(cols) == 0
throw(ArgumentError("At least one column must be passed to filter on"))
end
return deleterows!(df, findall(((x...) -> !(f(x...)::Bool)).(cols...)))
return delete!(df, findall(((x...) -> !(f(x...)::Bool)).(cols...)))
end

function Base.filter!((cols, f)::Pair{<:AsTable}, df::AbstractDataFrame)
Expand All @@ -1066,7 +1066,7 @@ function Base.filter!((cols, f)::Pair{<:AsTable}, df::AbstractDataFrame)
end

_filter!_helper_astable(df::AbstractDataFrame, nti::Tables.NamedTupleIterator, f) =
deleterows!(df, findall((x -> !(f(x)::Bool)).(nti)))
delete!(df, findall((x -> !(f(x)::Bool)).(nti)))

function Base.convert(::Type{Matrix}, df::AbstractDataFrame)
T = reduce(promote_type, (eltype(v) for v in eachcol(df)))
Expand Down Expand Up @@ -1139,11 +1139,11 @@ end

nonunique(df::AbstractDataFrame, cols) = nonunique(select(df, cols, copycols=false))

Base.unique!(df::AbstractDataFrame) = deleterows!(df, findall(nonunique(df)))
Base.unique!(df::AbstractDataFrame) = delete!(df, findall(nonunique(df)))
Base.unique!(df::AbstractDataFrame, cols::AbstractVector) =
deleterows!(df, findall(nonunique(df, cols)))
delete!(df, findall(nonunique(df, cols)))
Base.unique!(df::AbstractDataFrame, cols) =
deleterows!(df, findall(nonunique(df, cols)))
delete!(df, findall(nonunique(df, cols)))

# Unique rows of an AbstractDataFrame.
Base.unique(df::AbstractDataFrame) = df[(!).(nonunique(df)), :]
Expand Down
8 changes: 4 additions & 4 deletions src/dataframe/dataframe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ function Base.copy(df::DataFrame; copycols::Bool=true)
end

"""
deleterows!(df::DataFrame, inds)
delete!(df::DataFrame, inds)

Delete rows specified by `inds` from a `DataFrame` `df` in place and return it.

Expand All @@ -776,7 +776,7 @@ julia> d = DataFrame(a=1:3, b=4:6)
│ 2 │ 2 │ 5 │
│ 3 │ 3 │ 6 │

julia> deleterows!(d, 2)
julia> delete!(d, 2)
2×2 DataFrame
│ Row │ a │ b │
│ │ Int64 │ Int64 │
Expand All @@ -786,7 +786,7 @@ julia> deleterows!(d, 2)
```

"""
function deleterows!(df::DataFrame, inds)
function Base.delete!(df::DataFrame, inds)
if !isempty(inds) && size(df, 2) == 0
throw(BoundsError(df, (inds, :)))
end
Expand All @@ -795,7 +795,7 @@ function deleterows!(df::DataFrame, inds)
df
end

function deleterows!(df::DataFrame, inds::AbstractVector{Bool})
function Base.delete!(df::DataFrame, inds::AbstractVector{Bool})
if length(inds) != size(df, 1)
throw(BoundsError(df, (inds, :)))
end
Expand Down
5 changes: 3 additions & 2 deletions src/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,8 @@ import Base: show
@deprecate showall(io::IO, df::GroupedDataFrame) show(io, df, allgroups=true)
@deprecate showall(df::GroupedDataFrame) show(df, allgroups=true)

import Base: delete!, insert!, merge!
import Base: insert!, merge!

@deprecate delete!(df::AbstractDataFrame, cols::Any) select!(df, Not(cols))
@deprecate insert!(df::DataFrame, col_ind::Int, item, name::Symbol; makeunique::Bool=false) insertcols!(df, col_ind, name => item; makeunique=makeunique)
@deprecate merge!(df1::DataFrame, df2::AbstractDataFrame) (foreach(col -> df1[!, col] = df2[!, col], names(df2)); df1)

Expand Down Expand Up @@ -357,3 +356,5 @@ function by(d::AbstractDataFrame, cols::Any; sort::Bool=false, skipmissing::Bool
end

@deprecate groupvars(gd::GroupedDataFrame) groupcols(gd)

@deprecate deleterows!(df::DataFrame, inds) delete!(df, inds)
2 changes: 1 addition & 1 deletion src/subdataframe/subdataframe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ Base.@propagate_inbounds Base.setindex!(sdf::SubDataFrame, val::Any, rowinds::Bo

Base.copy(sdf::SubDataFrame) = parent(sdf)[rows(sdf), parentcols(index(sdf), :)]

deleterows!(df::SubDataFrame, ind) =
Base.delete!(df::SubDataFrame, ind) =
throw(ArgumentError("SubDataFrame does not support deleting rows"))

function DataFrame(sdf::SubDataFrame; copycols::Bool=true)
Expand Down
48 changes: 24 additions & 24 deletions test/dataframe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -508,93 +508,93 @@ end
@test_logs (:warn, r"In the future `push!` will not allow passing collections of type") push!(df, "ab")
end

@testset "deleterows!" begin
@testset "delete!" begin
df = DataFrame(a=[1, 2], b=[3.0, 4.0])
@test deleterows!(df, 1) === df
@test delete!(df, 1) === df
@test df == DataFrame(a=[2], b=[4.0])

df = DataFrame(a=[1, 2], b=[3.0, 4.0])
@test deleterows!(df, 2) === df
@test delete!(df, 2) === df
@test df == DataFrame(a=[1], b=[3.0])

df = DataFrame(a=[1, 2, 3], b=[3.0, 4.0, 5.0])
@test deleterows!(df, 2:3) === df
@test delete!(df, 2:3) === df
@test df == DataFrame(a=[1], b=[3.0])

df = DataFrame(a=[1, 2, 3], b=[3.0, 4.0, 5.0])
@test deleterows!(df, [2, 3]) === df
@test delete!(df, [2, 3]) === df
@test df == DataFrame(a=[1], b=[3.0])

df = DataFrame(a=Union{Int, Missing}[1, 2], b=Union{Float64, Missing}[3.0, 4.0])
@test deleterows!(df, 1) === df
@test delete!(df, 1) === df
@test df == DataFrame(a=[2], b=[4.0])

df = DataFrame(a=Union{Int, Missing}[1, 2], b=Union{Float64, Missing}[3.0, 4.0])
@test deleterows!(df, 2) === df
@test delete!(df, 2) === df
@test df == DataFrame(a=[1], b=[3.0])

df = DataFrame(a=Union{Int, Missing}[1, 2, 3], b=Union{Float64, Missing}[3.0, 4.0, 5.0])
@test deleterows!(df, 2:3) === df
@test delete!(df, 2:3) === df
@test df == DataFrame(a=[1], b=[3.0])

df = DataFrame(a=Union{Int, Missing}[1, 2, 3], b=Union{Float64, Missing}[3.0, 4.0, 5.0])
@test deleterows!(df, [2, 3]) === df
@test delete!(df, [2, 3]) === df
@test df == DataFrame(a=[1], b=[3.0])

df = DataFrame()
@test_throws BoundsError deleterows!(df, 10)
@test_throws BoundsError deleterows!(df, [10])
@test_throws BoundsError delete!(df, 10)
@test_throws BoundsError delete!(df, [10])

df = DataFrame(a=[])
@test_throws BoundsError deleterows!(df, 10)
@test_throws BoundsError delete!(df, 10)
# the exception type changed between Julia 1.0.2 and Julia 1.1
# so we use their supertype below
@test_throws Exception deleterows!(df, [10])
@test_throws Exception delete!(df, [10])

df = DataFrame(a=[1, 2, 3], b=[3, 2, 1])
@test_throws ArgumentError deleterows!(df, [3,2])
@test_throws ArgumentError deleterows!(df, [2,2])
@test deleterows!(df, [false, true, false]) === df
@test_throws ArgumentError delete!(df, [3,2])
@test_throws ArgumentError delete!(df, [2,2])
@test delete!(df, [false, true, false]) === df
@test df == DataFrame(a=[1, 3], b=[3, 1])

x = [1, 2, 3]
df = DataFrame(x=x)
@test deleterows!(df, 1) == DataFrame(x=[2, 3])
@test delete!(df, 1) == DataFrame(x=[2, 3])
@test x == [1, 2, 3]

x = [1, 2, 3]
df = DataFrame(x=x)
@test deleterows!(df, [1]) == DataFrame(x=[2, 3])
@test delete!(df, [1]) == DataFrame(x=[2, 3])
@test x == [1, 2, 3]

x = [1, 2, 3]
df = DataFrame(x=x)
@test deleterows!(df, 1:1) == DataFrame(x=[2, 3])
@test delete!(df, 1:1) == DataFrame(x=[2, 3])
@test x == [1, 2, 3]

x = [1, 2, 3]
df = DataFrame(x=x)
@test deleterows!(df, [true, false, false]) == DataFrame(x=[2, 3])
@test delete!(df, [true, false, false]) == DataFrame(x=[2, 3])
@test x == [1, 2, 3]

x = [1, 2, 3]
df = DataFrame(x=x, copycols=false)
@test deleterows!(df, 1) == DataFrame(x=[2, 3])
@test delete!(df, 1) == DataFrame(x=[2, 3])
@test x == [2, 3]

x = [1, 2, 3]
df = DataFrame(x=x, copycols=false)
@test deleterows!(df, [1]) == DataFrame(x=[2, 3])
@test delete!(df, [1]) == DataFrame(x=[2, 3])
@test x == [2, 3]

x = [1, 2, 3]
df = DataFrame(x=x, copycols=false)
@test deleterows!(df, 1:1) == DataFrame(x=[2, 3])
@test delete!(df, 1:1) == DataFrame(x=[2, 3])
@test x == [2, 3]

x = [1, 2, 3]
df = DataFrame(x=x, copycols=false)
@test deleterows!(df, [true, false, false]) == DataFrame(x=[2, 3])
@test delete!(df, [true, false, false]) == DataFrame(x=[2, 3])
@test x == [2, 3]
end

Expand Down
6 changes: 6 additions & 0 deletions test/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -635,4 +635,10 @@ end

global_logger(old_logger)

@testset "deprecated deleterows!" begin
@test deleterows!(DataFrame(x=[1, 2]), 1) ==
deleterows!(DataFrame(x=[1, 2]), [1]) ==
deleterows!(DataFrame(x=[1, 2]), [true, false]) == DataFrame(x=[2])
end

end # module
4 changes: 2 additions & 2 deletions test/subdataframe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,10 @@ end
@test names(df) == names(x)[[4,2]]
end

@testset "deleterows!" begin
@testset "delete!" begin
y = 1.0:10.0
df = view(DataFrame(y=y), 2:6, :)
@test_throws ArgumentError deleterows!(df, 1)
@test_throws ArgumentError delete!(df, 1)
end

@testset "parent" begin
Expand Down