Skip to content

fix(csv): warn when a data row has more columns than the header - #2391

Open
Lazizbek Ergashev (lazerg) wants to merge 2 commits into
microsoft:mainfrom
lazerg:fix/issue-2390-csv-column-mismatch-warning
Open

fix(csv): warn when a data row has more columns than the header#2391
Lazizbek Ergashev (lazerg) wants to merge 2 commits into
microsoft:mainfrom
lazerg:fix/issue-2390-csv-column-mismatch-warning

Conversation

@lazerg

Copy link
Copy Markdown
Contributor

CsvConverter treats rows[0] as the header with no validation, so a data row with extra columns just gets truncated with row[: len(rows[0])], dropping fields silently. WizTree exports hit this in practice: their CSV starts with a one-field banner line before the real header, so every real column after the first gets dropped without any indication something went wrong.

This adds a warning when that truncation happens, so the data loss is visible instead of silent. The truncation behavior itself is unchanged.

Fixes #2390

…ilter("error")

Review found the negative regression test for the row-width warning was
promoting every warning to an error, not just the one under test, which
could make it fail for unrelated reasons. Switch to the
catch_warnings(record=True) + simplefilter("always") pattern already used
by the other warning regression tests in this file.
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.

CSV converter silently truncates data columns when rows have more fields than the header row

1 participant