Skip to content

Commit

Permalink
Deprecate empty! (#1843)
Browse files Browse the repository at this point in the history
So that we can change it to be equivalent to `empty!.(eachcol(df))`.
  • Loading branch information
nalimilan authored Jun 12, 2019
1 parent 724d132 commit 25e23b7
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
4 changes: 1 addition & 3 deletions src/dataframe/dataframe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -707,12 +707,10 @@ Base.setindex!(df::DataFrame, v, ::Colon, col_inds) =

##############################################################################
##
## Mutating AbstractDict methods
## Mutating methods
##
##############################################################################

Base.empty!(df::DataFrame) = (empty!(_columns(df)); empty!(index(df)); df)

"""
Insert a column into a data frame in place.
Expand Down
3 changes: 3 additions & 0 deletions src/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1400,3 +1400,6 @@ import Base: get

import Base: haskey
@deprecate haskey(df::AbstractDataFrame, key::Any) key in names(df)

import Base: empty!
@deprecate empty!(df::DataFrame) deletecols!(df, 1:ncol(df))
12 changes: 1 addition & 11 deletions test/dataframe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,7 @@ end
@test size(similar(df, 2)) == size(missingdf)
end

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

dfv = view(df, 1:2, 1:2)

@test empty!(df) === df
@test isempty(eachcol(df))
@test isempty(df)
@test isempty(DataFrame(a=[], b=[]))

@testset "insertcols!" begin
df = DataFrame(a=Union{Int, Missing}[1, 2], b=Union{Float64, Missing}[3.0, 4.0])
@test_throws BoundsError insertcols!(df, 5, :newcol => ["a", "b"], )
@test_throws ErrorException insertcols!(df, 1, :newcol => ["a"])
Expand Down
14 changes: 13 additions & 1 deletion test/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,16 @@ df = DataFrame(Union{Int, Missing}, 2, 2)
end
end

end # module
@testset "empty!" begin
df = DataFrame(a=[1, 2], b=[3.0, 4.0])
@test !isempty(df)

dfv = view(df, 1:2, 1:2)

@test empty!(df) === df
@test isempty(eachcol(df))
@test isempty(df)
@test isempty(DataFrame(a=[], b=[]))
end

end # module

0 comments on commit 25e23b7

Please sign in to comment.