fix(frame): add size and duplicate-name guards to Frame::add_column - #937
Conversation
There was a problem hiding this comment.
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→ PythonValueError). - 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
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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
mainand resolve the conflicts incpp/src/frame.cppandtests/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
dad51fc to
ebce230
Compare
|
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
left a comment
There was a problem hiding this comment.
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.
Summary
Fixes #925
Problem
Frame::add_columnlacked 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.pytest_add_column_rejects_duplicate_name— ensures adding a column with an existing name raisesValueError.Existing tests already cover:
ValueErrorDiff scope
1 file changed —
tests/test_frame.py(+19 lines)