Closed zhezhaozz closed 1 year ago
Selection helper functions such as contains and startswith do not work within across. For example:
contains
startswith
across
@chain df begin @mutate(across((b, startswith("c")), (minimum, maximum))) end
This will throw an error message:
[ Info: transform($(Expr(:escape, :raccoon)), Cols(:b, $(Expr(:escape, :(starts_with("c"))))) .=> reshape([$(Expr(:escape, :minimum)), $(Expr(:escape, :maximum))], 1, 2)) ERROR: ArgumentError: invalid index: Base.Fix2{typeof(startswith), String}(startswith, "c") of type Base.Fix2{typeof(startswith), String} Stacktrace: [1] getindex @ ~/.julia/packages/DataFrames/dgZn3/src/other/index.jl:185 [inlined] [2] _broadcast_getindex_evalf @ ./broadcast.jl:670 [inlined] [3] _broadcast_getindex @ ./broadcast.jl:643 [inlined] [4] (::Base.Broadcast.var"#29#30"{Base.Broadcast.Broadcasted{Base.Broadcast.Style{Tuple}, Nothing, typeof(getindex), Tuple{Base.RefValue{DataFrames.Index}, Tuple{Symbol, Base.Fix2{typeof(startswith), String}}}}})(k::Int64) @ Base.Broadcast ./broadcast.jl:1075 [5] ntuple @ ./ntuple.jl:49 [inlined] [6] copy @ ./broadcast.jl:1075 [inlined] [7] materialize @ ./broadcast.jl:860 [inlined] [8] getindex @ ~/.julia/packages/DataFrames/dgZn3/src/other/index.jl:232 [inlined] [9] names(df::DataFrame, cols::Cols{Tuple{Symbol, Base.Fix2{typeof(startswith), String}}}) @ DataFrames ~/.julia/packages/DataFrames/dgZn3/src/abstractdataframe/abstractdataframe.jl:102 [10] broadcast_pair(df::DataFrame, p::AbstractVecOrMat{<:Pair}) @ DataFrames ~/.julia/packages/DataFrames/dgZn3/src/abstractdataframe/selection.jl:274 [11] #548 @ ~/.julia/packages/DataFrames/dgZn3/src/abstractdataframe/selection.jl:1286 [inlined] [12] map(f::DataFrames.var"#548#549"{DataFrame}, t::Tuple{Colon, Matrix{Pair{DataAPI.BroadcastedSelector{Cols{Tuple{Symbol, Base.Fix2{typeof(startswith), String}}}}}}}) @ Base ./tuple.jl:222 [13] select(::DataFrame, ::Any, ::Vararg{Any}; copycols::Bool, renamecols::Bool, threads::Bool) @ DataFrames ~/.julia/packages/DataFrames/dgZn3/src/abstractdataframe/selection.jl:1285 [14] #transform#551 @ ~/.julia/packages/DataFrames/dgZn3/src/abstractdataframe/selection.jl:1365 [inlined] [15] transform(df::DataFrame, args::Any) @ DataFrames ~/.julia/packages/DataFrames/dgZn3/src/abstractdataframe/selection.jl:1365 [16] top-level scope @ REPL[27]:476
This error is due to the outdated version of DataFrames.jl.
DataFrames.jl
Make sure your DataFrames.jl is updated (v1.5.0).
Selection helper functions such as
contains
andstartswith
do not work withinacross
. For example:This will throw an error message: