Skip to content

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

Open
Manohar Paturi (ManoharPaturi) wants to merge 2 commits into
microsoft:mainfrom
ManoharPaturi:fix/csv-helper-union-fieldnames
Open

Manohar Paturi (ManoharPaturi) wants to merge 2 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.

This branch has not been deployed

No deployments
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

1 participant