Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Milan Bouchet-Valat <[email protected]>
  • Loading branch information
bkamins and nalimilan authored Oct 14, 2023
1 parent beb9563 commit 266448d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 7 additions & 5 deletions src/abstractdataframe/iteration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,8 @@ Base.show(dfcs::DataFrameColumns;
"""
mapcols(f::Union{Function, Type}, df::AbstractDataFrame; cols=All())
Return a `DataFrame` where each column of `df` selected by `cols` is transformed using function `f`.
Return a `DataFrame` where each column of `df` selected by `cols` (by default, all columns)
is transformed using function `f`.
Columns not selected by `cols` are copied.
`f` must return `AbstractVector` objects all with the same length or scalars
Expand Down Expand Up @@ -445,7 +446,7 @@ julia> mapcols(x -> x.^2, df)
3 │ 9 169
4 │ 16 196
julia> mapcols(x -> x.^2, df, cols="y")
julia> mapcols(x -> x.^2, df, cols=r"y")
4×2 DataFrame
Row │ x y
│ Int64 Int64
Expand All @@ -457,7 +458,7 @@ julia> mapcols(x -> x.^2, df, cols="y")
```
"""
function mapcols(f::Union{Function, Type}, df::AbstractDataFrame; cols=All())
if cols == All() || cols == Colon()
if cols === All() || cols === Colon()
apply = fill(true, ncol(df))
else
picked = Set(names(df, cols))
Expand Down Expand Up @@ -494,7 +495,8 @@ end
"""
mapcols!(f::Union{Function, Type}, df::DataFrame; cols=All())
Update a `DataFrame` in-place where each column of `df` selected by `cols` is transformed using function `f`.
Update a `DataFrame` in-place where each column of `df` selected by `cols` (by default, all columns)
is transformed using function `f`.
Columns not selected by `cols` are left unchanged.
`f` must return `AbstractVector` objects all with the same length or scalars
Expand Down Expand Up @@ -528,7 +530,7 @@ julia> df
3 │ 9 169
4 │ 16 196
julia> mapcols!(x -> 2 * x, df, cols="x");
julia> mapcols!(x -> 2 * x, df, cols=r"x");
julia> df
4×2 DataFrame
Expand Down
2 changes: 1 addition & 1 deletion test/iteration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ end
a1, a2, b = eachcol(df)
mapcols!(x -> 2x, df, cols=Not(All()))
@test df == DataFrame(a1=[1, 2], a2=[2, 3], b=[3, 4])
@test df.a1 == a1 && df.a2 == a2 && df.b == b
@test df.a1 === a1 && df.a2 === a2 && df.b === b
end

@testset "SubDataFrame" begin
Expand Down

0 comments on commit 266448d

Please sign in to comment.