Skip to content

Fix csvformat header options on empty input - #1360

Open
umd0730 wants to merge 1 commit into
wireservice:masterfrom
umd0730:fix/csvformat-empty-header-options
Open

umd0730 wants to merge 1 commit into
wireservice:masterfrom
umd0730:fix/csvformat-empty-header-options

Conversation

@umd0730

@umd0730 umd0730 commented Sep 16, 2026

Copy link
Copy Markdown

csvformat --skip-header and csvformat --no-header-row raise StopIteration on a zero-byte input. The same failure happens if --skip-lines consumes the whole input. This breaks pipelines whose upstream filter produces no rows.

Handle exhaustion when peeking for generated headers and when skipping an optional header. Empty input now produces no output; existing nonempty and blank-record behavior is unchanged.

Validation on Windows / Python 3.12.14 with agate 1.14.2:

  • Before the fix, both added regression tests failed with StopIteration.
  • After the fix, PYTHONUTF8=1 python -m pytest tests -q --tb=short --disable-warnings: 357 passed.
  • Tests exercise all three combinations of --skip-header / --no-header-row, on zero-byte stdin and after skipping every input line.
  • check-manifest, flake8 . and isort . --check-only all passed locally.
  • Without UTF-8 mode, 14 unrelated tests fail reading UTF-8 expected files with the Windows CP932 default. The passing run uses Python's UTF-8 mode; no unrelated encoding changes are included.

Includes a changelog entry. Tested against current master ba8033dcbb2c72089e88f38a1a50ddfc8e5ac3df.

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.

1 participant