Skip to content

fix(frame): add size and duplicate-name guards to Frame::add_column - #937

Merged
im-anishraj merged 1 commit into
im-anishraj:mainfrom
adityashirsatrao007:fix/add-column-size-guard-925
May 21, 2026
Merged

fix(frame): add size and duplicate-name guards to Frame::add_column#937
im-anishraj merged 1 commit into
im-anishraj:mainfrom
adityashirsatrao007:fix/add-column-size-guard-925

Conversation

@adityashirsatrao007

@adityashirsatrao007 adityashirsatrao007 commented May 20, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #925

Problem

Frame::add_column lacked row-count validation and duplicate-name checking, causing memory corruption and inconsistent frame state.

Changes

Both C++ guards (size validation + duplicate-name check) are already present in main. This PR adds the missing regression test:

tests/test_frame.py

  • Added test_add_column_rejects_duplicate_name — ensures adding a column with an existing name raises ValueError.

Existing tests already cover:

  • ✅ valid same-length columns accepted
  • ✅ mismatched-length columns rejected with ValueError
  • ✅ first column in empty frame accepted at any size
  • ✅ zero-row explicit frame rejects nonempty first column

Diff scope

1 file changed — tests/test_frame.py (+19 lines)

Copilot AI review requested due to automatic review settings May 20, 2026 16:33

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR hardens the C++ Frame::add_column API to prevent internal inconsistency and potential memory corruption when adding columns via the pybind-exposed core types (fixing #925).

Changes:

  • Rejects adding a column whose row count doesn’t match the existing frame (when non-empty).
  • Rejects adding a column whose name already exists in the frame (std::invalid_argument → Python ValueError).
  • Adds a Python test that locks in the duplicate-name rejection behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
cpp/src/frame.cpp Adds a duplicate-name guard (and retains row-count validation) in Frame::add_column to preserve frame invariants.
tests/test_frame.py Adds coverage for rejecting duplicate column names through the pybind-exposed Frame.add_column.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@im-anishraj im-anishraj left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks for tightening this down to the duplicate-name guard while preserving the existing size guard behavior. The diff is focused, the regression test covers the duplicate-name path, and the full repository CI/wheel matrix is green.

I also attempted a targeted local validation in a clean temp worktree, but this machine cannot currently build the extension: MSVC/NMake is not available on PATH, and the available MinGW is too old for the project C++17 headers (<variant>/<optional>). So I am approving the code review based on the clean diff plus green CI, but I am not merging it from this environment.

@adityashirsatrao007

Copy link
Copy Markdown
Contributor Author

Thanks for tightening this down to the duplicate-name guard while preserving the existing size guard behavior. The diff is focused, the regression test covers the duplicate-name path, and the full repository CI/wheel matrix is green.

I also attempted a targeted local validation in a clean temp worktree, but this machine cannot currently build the extension: MSVC/NMake is not available on PATH, and the available MinGW is too old for the project C++17 headers (<variant>/<optional>). So I am approving the code review based on the clean diff plus green CI, but I am not merging it from this environment.

Thanks for the detailed review and approval. Understood regarding the local environment limitations. I’ll keep an eye on the PR in case any follow-up changes are needed.

@im-anishraj im-anishraj left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks for the focused guard. I rechecked this against the current main after today’s merges, and the branch no longer merges cleanly.

Blocker before merge:

  • Please sync/rebase with the latest main and resolve the conflicts in cpp/src/frame.cpp and tests/test_frame.py. The conflict blocks the required local merge-result validation, including the MSVC native build/tests and Python test gate.

Once the PR is clean again, I will rerun the native + Python validation before making a merge decision.

- add_column now throws std::invalid_argument (-> ValueError in Python)
  when a column with a mismatched row count is added to a non-empty frame
- add_column now also throws std::invalid_argument when a column name
  already exists, preventing silent name_index_ corruption
- the first-column baseline behaviour is preserved: any size is accepted
  when the frame is empty
- add test_add_column_rejects_duplicate_name to lock in the new guard

Fixes #925
@adityashirsatrao007
adityashirsatrao007 force-pushed the fix/add-column-size-guard-925 branch from dad51fc to ebce230 Compare May 21, 2026 18:26
@im-anishraj

Copy link
Copy Markdown
Owner

Thanks for rebasing this. The branch is mergeable now, and I approved the pending workflow runs for the new head. I’ll wait for CI/wheel checks to report green before running the local validation pass and reconsidering the review.

@im-anishraj im-anishraj left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks for rebasing. I validated the current merge result locally on Windows with Python 3.12/MSVC: editable install with dev/parquet extras, targeted ests/test_frame.py -k add_column, full pytest, Black, Ruff, and mypy all pass. CI is green too, so this is ready.

@im-anishraj
im-anishraj merged commit aad33d7 into im-anishraj:main May 21, 2026
23 checks passed
@im-anishraj im-anishraj added type:testing GSSoC scoring label for tests and testing contributions area:cpp-core C++ Frame, Column, pybind11, memory, and core engine internals backend Backend, Python API, C++ core, parser, data engine, or library runtime work testing Test coverage and quality gssoc Part of the GSSoC 2026 contributor program gssoc:approved Merged and approved GSSoC contribution gssoc:level-1 GSSoC beginner-level task level:beginner GSSoC scoring label for beginner-level merged PRs quality:clean GSSoC scoring label for clean, well-scoped merged PRs size:xs Tiny change; often docs, tests, validation, or one small fix labels May 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:cpp-core C++ Frame, Column, pybind11, memory, and core engine internals backend Backend, Python API, C++ core, parser, data engine, or library runtime work gssoc:approved Merged and approved GSSoC contribution gssoc:level-1 GSSoC beginner-level task gssoc Part of the GSSoC 2026 contributor program level:beginner GSSoC scoring label for beginner-level merged PRs quality:clean GSSoC scoring label for clean, well-scoped merged PRs size:xs Tiny change; often docs, tests, validation, or one small fix testing Test coverage and quality type:testing GSSoC scoring label for tests and testing contributions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: Frame::add_column lacks size validation, leading to out-of-bounds C++ memory access/crashes

3 participants