Repository navigation
Fix TypeError for headers='keys' with iterator rows (#515) - #516
Open
thejedi433 wants to merge 1 commit into
Open
thejedi433 wants to merge 1 commit into
thejedi433 wants to merge 1 commit into
Conversation
_normalize_tabular_data computed column-index headers via len(rows[0]) before rows were materialized to lists, so an iterable of iterators (map/iter/generator rows) crashed with TypeError: object of type 'list_iterator' has no len() even though the same input rendered fine with the default headers. Materialize rows[0] when it has no __len__ (no-op for list/ tuple rows, single-use-safe for generators whose rows are themselves iterators). 3 regression tests: iterator rows, generator-of-iterators, ragged iterator rows; verified red->green on the full suite (309 passed, 60 skipped).
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.
Fixes #515
headers="keys"raisedTypeError: object of type 'list_iterator' has no len()when rows were iterators, because_normalize_tabular_datacomputed the column-index headers withlen(rows[0])a few lines before the generalrows = [list(r) ...]materialization. The same input renders fine with default headers, so the README's "iterable of iterables" contract was silently violated for this one headers mode.Repro on pristine master (268615a):
Fix: materialize
rows[0]into a list when it has no__len__before taking its length. No-op for list/tuple rows, and safe for single-use iterator rows (this also covers the generator-of-iterators case where the rows can't be replayed — verified: the values are consumed exactly once and appear in the output).Scoping check against open PRs: none of the 25 open PRs touch #515 (searched for "515", iterator/len fixes); the closest ones (#504/#482, ragged-column handling) don't reach this line. No competing attempt on closed PRs either.
Tests: 3 regression tests in
test/test_input.py(iterator rows, generator-of-iterators, ragged iterator rows). Verified RED on pre-fix tree (3 failures, TypeError) / GREEN post-fix; full suite 309 passed / 60 skipped, identical to baseline.ruff@0.6 checkclean on the test file (the 10 ISC001 warnings in__init__.pyare pre-existing baseline),ruff format --checkclean.