Skip to content

Commit

Permalink
mapcols!(): exit early if no columns
Browse files Browse the repository at this point in the history
fixes #2474
  • Loading branch information
alyst committed Oct 9, 2020
1 parent 4ec8009 commit 48c3032
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/abstractdataframe/iteration.jl
Expand Up @@ -411,6 +411,8 @@ julia> df
"""
function mapcols!(f::Union{Function,Type}, df::DataFrame)
# note: `f` must return a consistent length
(ncol(df) == 0) && return df # skip if no columns

vs = AbstractVector[]
seenscalar = false
seenvector = false
Expand Down
5 changes: 4 additions & 1 deletion test/iteration.jl
Expand Up @@ -71,8 +71,11 @@ end
end

@testset "mapcols!" begin
df_empty = DataFrame()
@test mapcols!(sum, df_empty) === df_empty

df_mapcols = DataFrame(a=1:10, b=11:20)
mapcols!(sum, df_mapcols)
@test mapcols!(sum, df_mapcols) === df_mapcols
@test df_mapcols == DataFrame(a=55, b=155)

df_mapcols = DataFrame(a=1:10, b=11:20)
Expand Down

0 comments on commit 48c3032

Please sign in to comment.