Skip to content

Reject transformations on SubDataFrame with copycols=false#3522

Merged
bkamins merged 10 commits intoJuliaData:mainfrom
arkgupta17:improve-subdataframe-copycols-error
Feb 22, 2026
Merged

Reject transformations on SubDataFrame with copycols=false#3522
bkamins merged 10 commits intoJuliaData:mainfrom
arkgupta17:improve-subdataframe-copycols-error

Conversation

@arkgupta17
Copy link
Copy Markdown
Contributor

This PR rejects transformations on SubDataFrame when copycols=false and adds a regression test ensuring a clear ArgumentError mentioning copycols=false

@bkamins
Copy link
Copy Markdown
Member

bkamins commented Feb 4, 2026

Fixes #3515

@bkamins bkamins linked an issue Feb 4, 2026 that may be closed by this pull request
Copy link
Copy Markdown
Member

@bkamins bkamins left a comment

Choose a reason for hiding this comment

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

Thank you for the PR. It catches a bug that we have. I have left some suggestions.

return newdf
end

function manipulate(dfv::SubDataFrame, @nospecialize(args...); copycols::Bool, keeprows::Bool,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

could you please remove changes that are only for layout reasons? This will simplify analysis of commits to main in the future. Thank you!.

Comment on lines 1847 to 1852
push!(newinds, ind_idx)
else
newind = index(dfv)[ind]
push!(newinds, newind)
end
end
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
push!(newinds, ind_idx)
else
newind = index(dfv)[ind]
push!(newinds, newind)
end
end
end
newind = index(dfv)[ind]
push!(newinds, newind)
end

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is a good catch. The following change is needed in the code. (just please check the alignment of lines as I edit in a browser).

Also can you please add the following test:

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

julia> v = @view df[1:2, :]
2×2 SubDataFrame
 Row │ a      b
     │ Int64  Int64
─────┼──────────────
   1 │     1      1
   2 │     2      2

julia> select(v, "a", "b", copycols=false)
newinds = Any[]
0×0 SubDataFrame

this is on main and it is incorrect as you see as the result should be:

2×2 DataFrame
 Row │ a      b
     │ Int64  Int64
─────┼──────────────
   1 │     1      1
   2 │     2      2

@bkamins bkamins added the bug label Feb 4, 2026
@bkamins bkamins added this to the patch milestone Feb 4, 2026
@arkgupta17 arkgupta17 force-pushed the improve-subdataframe-copycols-error branch from e4f6745 to 3ab53c7 Compare February 6, 2026 07:38
@arkgupta17
Copy link
Copy Markdown
Contributor Author

Thanks for pointing that out — you’re absolutely right.

I’ve removed all layout-only changes and reverted the file to upstream formatting.
The commit now contains only the minimal functional fix for copycols=false column selection on SubDataFrame, plus the regression test you requested.

Please let me know if this looks good now.

@bkamins
Copy link
Copy Markdown
Member

bkamins commented Feb 6, 2026

Thank you! I added one small suggestion. Otherwise it looks good. Do you know why nightly fails?

Co-authored-by: Bogumił Kamiński <bkamins@sgh.waw.pl>
@arkgupta17
Copy link
Copy Markdown
Contributor Author

Thank you for the review and the suggestion — I’ve applied it.

I’m not sure yet why nightly fails. I’ll investigate the nightly logs locally and report back once I understand the cause.

@arkgupta17 arkgupta17 requested a review from bkamins February 6, 2026 12:11
@bkamins
Copy link
Copy Markdown
Member

bkamins commented Feb 6, 2026

OK - I understand that === fails, so maybe let us check == and check if parent of columns is ===.

Copy link
Copy Markdown
Member

@bkamins bkamins left a comment

Choose a reason for hiding this comment

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

Looks good. Thank you! The nightly fail is unrelated.

@bkamins bkamins requested a review from nalimilan February 12, 2026 08:57
arkgupta17 and others added 4 commits February 15, 2026 22:28
Co-authored-by: Milan Bouchet-Valat <nalimilan@club.fr>
Co-authored-by: Milan Bouchet-Valat <nalimilan@club.fr>
Co-authored-by: Milan Bouchet-Valat <nalimilan@club.fr>
@arkgupta17 arkgupta17 force-pushed the improve-subdataframe-copycols-error branch from ae7dacd to 1964644 Compare February 15, 2026 17:44
newinds = Any[]
seen_single_column = Set{Int}()
for ind in args
if ind isa Pair || ind isa AbstractVecOrMat{<:Pair}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

still some indentation issues here

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is still the place where the issue is. The code is indended by 3 spaces and should be by 4

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have fixed the issue.

Thank you!

@arkgupta17 arkgupta17 requested a review from bkamins February 21, 2026 15:10
@bkamins
Copy link
Copy Markdown
Member

bkamins commented Feb 21, 2026

Hi,

I think you accenditenally run some autoformatter. I requested to fix just one place where indentation was incorrect. Could you please revert last commit and just fix the indentation in the PR? Thank you!

@arkgupta17 arkgupta17 force-pushed the improve-subdataframe-copycols-error branch from 346bc91 to a04f14b Compare February 21, 2026 20:41
@bkamins
Copy link
Copy Markdown
Member

bkamins commented Feb 21, 2026

The changes are not reverted

@arkgupta17 arkgupta17 force-pushed the improve-subdataframe-copycols-error branch from a04f14b to 1964644 Compare February 21, 2026 21:16
@arkgupta17
Copy link
Copy Markdown
Contributor Author

I have reset the branch to commit 1964644 and ensured only the intended indentation structure is present.

seen_single_column = Set{Int}()
for ind in args
if ind isa Pair || ind isa AbstractVecOrMat{<:Pair}
throw(ArgumentError(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

the PR still has wrong indentations. Sometimes 3 spaces, sometimes 2 spaces. Please make sure that in the PR all indentations are at 3 spaces. Thank you!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You mean 4 spaces, right? ;-)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think everything is fine now!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

4 spaces - right

@bkamins bkamins merged commit b12f7fb into JuliaData:main Feb 22, 2026
7 of 8 checks passed
@bkamins
Copy link
Copy Markdown
Member

bkamins commented Feb 22, 2026

Thank you!

@arkgupta17 arkgupta17 deleted the improve-subdataframe-copycols-error branch February 22, 2026 20:29
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.

invalid index with SubDataFrame and copycols = false

3 participants