-
Notifications
You must be signed in to change notification settings - Fork 373
Column insertion in DataFrameRow #3391
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
3ef44c0
6890681
eccd0b4
a141a71
f91b6d4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -259,11 +259,45 @@ for T in MULTICOLUMNINDEX_TUPLE | |||||||
| end | ||||||||
| end | ||||||||
|
|
||||||||
| Base.@propagate_inbounds Base.setindex!(r::DataFrameRow, value, idx) = | ||||||||
| setindex!(parent(r), value, row(r), parentcols(index(r), idx)) | ||||||||
|
|
||||||||
| index(r::DataFrameRow) = getfield(r, :colindex) | ||||||||
|
|
||||||||
| is_column_insertion_allowed(dfr::DataFrameRow) = index(dfr) isa Index | ||||||||
|
|
||||||||
| Base.@propagate_inbounds function Base.setindex!(dfr::DataFrameRow, value, idx) | ||||||||
| if idx isa SymbolOrString && columnindex(dfr, idx) == 0 | ||||||||
| if !is_column_insertion_allowed(dfr) | ||||||||
| throw(ArgumentError("creating new columns in a DataFrameRow that subsets " * | ||||||||
| "columns of its parent data frame is disallowed")) | ||||||||
| end | ||||||||
| T = typeof(val) | ||||||||
| newcol = similar(val, Union{T,Missing}, nrow(parent(dfr))) | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use Or maybe just call
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a very good point. I used Other places with the same issue are e.g.:
Do you think we should do a systematic review of them and fix this everywhere?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought we followed the policy that |
||||||||
| fill!(newcol, missing) | ||||||||
| newcol[row(dfr)] = val | ||||||||
| parent(dfr)[!, idx] = newcol | ||||||||
| else | ||||||||
| setindex!(parent(dfr), value, row(dfr), parentcols(index(dfr), idx)) | ||||||||
| end | ||||||||
| return dfr | ||||||||
| end | ||||||||
|
|
||||||||
| insertcols(dfr::DataFrameRow, args...; | ||||||||
| after::Bool=false, makeunique::Bool=false, copycols::Bool=true) = | ||||||||
bkamins marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||
| throw(ArgumentError("insertcols is not supported for DataFrameRow. " * | ||||||||
| "Maybe you wanted to use insertcols!?")) | ||||||||
|
|
||||||||
| function insertcols!(dfr::DataFrameRow, col::ColumnIndex, name_cols::Pair{Symbol}...; | ||||||||
| after::Bool=false, makeunique::Bool=false, copycols::Bool=false) | ||||||||
| if !is_column_insertion_allowed(dfr) | ||||||||
| throw(ArgumentError("creating new columns in a DataFrameRow that subsets " * | ||||||||
| "columns of its parent data frame is disallowed")) | ||||||||
| end | ||||||||
| r = row(dfr) | ||||||||
| insertcols!(view(parent(dfr), r:r, :), | ||||||||
| col, (k => [v] for (k,v) in name_cols)..., | ||||||||
| after=after, makeunique=makeunique, copycols=copycols) | ||||||||
| return dfr | ||||||||
| end | ||||||||
|
|
||||||||
| Base.names(r::DataFrameRow, cols::Colon=:) = names(index(r)) | ||||||||
|
|
||||||||
| function Base.names(r::DataFrameRow, cols) | ||||||||
|
|
||||||||
Uh oh!
There was an error while loading. Please reload this page.