Skip to content

deleteat! where drop is a column#3304

Merged
bkamins merged 6 commits intoJuliaData:mainfrom
gustafsson:deleteat-column
May 12, 2023
Merged

deleteat! where drop is a column#3304
bkamins merged 6 commits intoJuliaData:mainfrom
gustafsson:deleteat-column

Conversation

@gustafsson
Copy link
Copy Markdown
Contributor

deleteat!(df, df.what_to_drop) is broken unless df.what_to_drop is the last column.

julia> df = DataFrame(a=[false, true, true], b=1:3)
3×2 DataFrame
 Row │ a      b     
     │ Bool   Int64 
─────┼──────────────
   1 │ false      1
   2 │  true      2
   3 │  true      3

julia> deleteat!(df, df.a)
ERROR: BoundsError: attempt to access 3-element Vector{Int64} at index [false]
Stacktrace:
 [1] deleteat!(a::Vector{Int64}, inds::Vector{Bool})
   @ Base ./array.jl:1626
 [2] _deleteat!_helper(df::DataFrame, drop::Vector{Bool})
   @ DataFrames ~/.julia/packages/DataFrames/LteEl/src/dataframe/dataframe.jl:922
 [3] deleteat!(df::DataFrame, inds::Vector{Bool})
   @ DataFrames ~/.julia/packages/DataFrames/LteEl/src/dataframe/dataframe.jl:894
 [4] top-level scope
   @ REPL[40]:1

This PR creates a copy of which rows to drop when needed to avoid this.

@bkamins bkamins added the bug label Mar 18, 2023
@bkamins bkamins added this to the patch milestone Mar 18, 2023
@bkamins
Copy link
Copy Markdown
Member

bkamins commented May 3, 2023

@nalimilan - OK to merge?

@bkamins bkamins modified the milestones: patch, 1.6 May 3, 2023
Copy link
Copy Markdown
Member

@nalimilan nalimilan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like an extremely unlikely situation, but better be correct in that case of course. :-)

@bkamins bkamins merged commit 153c038 into JuliaData:main May 12, 2023
@bkamins
Copy link
Copy Markdown
Member

bkamins commented May 12, 2023

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants