Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deleteat! where drop is a column #3304

Merged
merged 6 commits into from
May 12, 2023
Merged

Conversation

gustafsson
Copy link
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.

src/dataframe/dataframe.jl Outdated Show resolved Hide resolved
@bkamins bkamins added the bug label Mar 18, 2023
@bkamins bkamins added this to the patch milestone Mar 18, 2023
@bkamins
Copy link
Member

bkamins commented May 3, 2023

@nalimilan - OK to merge?

@bkamins bkamins modified the milestones: patch, 1.6 May 3, 2023
Copy link
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. :-)

src/dataframe/dataframe.jl Outdated Show resolved Hide resolved
src/dataframe/dataframe.jl Outdated Show resolved Hide resolved
@bkamins bkamins merged commit 153c038 into JuliaData:main May 12, 2023
@bkamins
Copy link
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