Normalize ragged CSV to the widest row, not the header width#647
Open
gaoflow wants to merge 1 commit into
Open
Normalize ragged CSV to the widest row, not the header width#647gaoflow wants to merge 1 commit into
gaoflow wants to merge 1 commit into
Conversation
CSV import was documented (issue jazzband#226) to normalize ragged rows to the width of the widest row, but only padded rows up to the width of the first/header row. A data row wider than the header raised InvalidDimensions, while the shorter-row case was handled correctly. Compute the width across all rows and pad the header and every data row to it.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #647 +/- ##
==========================================
+ Coverage 93.19% 93.23% +0.04%
==========================================
Files 29 29
Lines 3247 3268 +21
==========================================
+ Hits 3026 3047 +21
Misses 221 221 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
CSV import is documented (issue #226) to normalize ragged rows "to the width of the widest row by filling in empty elements". In practice it only pads rows up to the width of the first/header row, so a data row wider than the header raises
InvalidDimensions:The analogous shorter case is handled — short rows are padded — so the behaviour is inconsistent, and the existing
test_csv_import_set_raggedonly exercises the header-is-widest direction.Fix
Read the header and data rows, compute the width as the maximum across all rows (header included), then pad the header and every data row to that width. Empty data lines are still skipped, and an empty/absent header still yields
headers=None.Verification
master(64f0201): a wider-than-header row raisesInvalidDimensions; with the fix it normalizes to the widest width (with and without headers).test_csv_import_set_ragged_wider_than_headerandtest_csv_import_set_ragged_wider_no_headers; both fail before the fix and pass after.ruff checkclean.test_csv_import_set_ragged, and empty-stream (headers=None) all unchanged.This completes the ragged-CSV feature from #226 for the wider-row case.
This pull request was prepared with the assistance of AI, under my direction and review.