From 266448dad27f33d46f0651b4e48806870f813685 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogumi=C5=82=20Kami=C5=84ski?= Date: Sat, 14 Oct 2023 20:44:24 +0200 Subject: [PATCH] Apply suggestions from code review Co-authored-by: Milan Bouchet-Valat --- src/abstractdataframe/iteration.jl | 12 +++++++----- test/iteration.jl | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/abstractdataframe/iteration.jl b/src/abstractdataframe/iteration.jl index f7809caa8..cf1d56ae3 100644 --- a/src/abstractdataframe/iteration.jl +++ b/src/abstractdataframe/iteration.jl @@ -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 @@ -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 @@ -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)) @@ -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 @@ -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 diff --git a/test/iteration.jl b/test/iteration.jl index 98848b36d..7b8290c50 100644 --- a/test/iteration.jl +++ b/test/iteration.jl @@ -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