Skip to content

Preserve headers when copying an empty table - #367

Open
OskarEichler wants to merge 2 commits into
ruby:mainfrom
OskarEichler:codex/csv-copy-headers
Open

Preserve headers when copying an empty table#367
OskarEichler wants to merge 2 commits into
ruby:mainfrom
OskarEichler:codex/csv-copy-headers

Conversation

@OskarEichler

Copy link
Copy Markdown

Summary

Pass the current headers to the new table in by_col, by_row, and by_col_or_row. Preserve the existing shallow row-copy behavior.

Reproduction

CSV.parse("a,b\n", headers: true).by_col.headers returns [] instead of ["a", "b"]; appending data then assigns nil headers. The same problem affects the other two non-mutating access-mode methods.

Verification

48 focused checks: 18 failures on the release, zero with the patch, covering empty tables, duplicate/nil/symbol headers, appends, and original-table isolation.

This isolated patch passes the unchanged upstream suite in both normal and CSV_PARSER_SCANNER_TEST=yes modes: 527 tests / 4,050 assertions in each mode, zero failures/errors. Commands use Ruby 4.0.6 through rbenv (bundle exec ruby run-test.rb). Syntax and git diff --check pass. The combined release-based consumer branch also passes gem build and rake warning:error rdoc.

No tests were added or changed, per the requesting project's explicit no-new-tests policy. Focused checks and measurements live outside this repository. The upstream no-RuboCop policy is respected. Verification was local on macOS/Ruby 4.0.6; the supported OS/Ruby matrix was not run locally. Current main and installed 3.3.6 share base commit 0873ab362d996f12796c3c3e8998b5be657a9b12; no unrelated changes are included.

Breaking changes and limitations

None intended. Empty table copies now retain their headers. Row ownership semantics are unchanged.

@kou

kou commented Aug 28, 2026

Copy link
Copy Markdown
Member

No tests were added or changed, per the requesting project's explicit no-new-tests policy.

Where is it written?

@kou

kou commented Aug 28, 2026

Copy link
Copy Markdown
Member

Do you have any real-world problem case by this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants