Skip to content

FIX: derive csv header from the union of row keys - #3304

Merged
Roman Lutz (romanlutz) merged 4 commits into
microsoft:mainfrom
ManoharPaturi:fix/csv-helper-union-fieldnames
Oct 19, 2026
Merged

Roman Lutz (romanlutz) merged 4 commits into
microsoft:mainfrom
ManoharPaturi:fix/csv-helper-union-fieldnames

Conversation

@ManoharPaturi

Copy link
Copy Markdown
Contributor

Description

Fixes #3303

write_csv took its fieldnames from the first row only, so a later row with an extra key made DictWriter raise after the header and earlier rows were already written, leaving a truncated file behind. The header now comes from the union of keys across all rows in first-seen order, and rows missing a key get an empty cell.

Tests and Documentation

Added two tests: one writes rows where only the second row has an extra key and asserts the round trip keeps every value, and one asserts the header keeps first seen column order when later rows introduce keys. Both fail on main and pass with the change. The full csv helper suite passes (9 tests).

No documentation change needed, so I did not run JupyText.

@romanlutz
Roman Lutz (romanlutz) added this pull request to the merge queue Oct 19, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 19, 2026
@romanlutz
Roman Lutz (romanlutz) added this pull request to the merge queue Oct 19, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 19, 2026
@romanlutz
Roman Lutz (romanlutz) merged commit 1cb972c into microsoft:main Oct 19, 2026
64 checks passed
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.

BUG: write_csv fails midway and leaves a partial file when later rows carry extra keys

2 participants