Repository navigation
Conversation
…n#494) When tabular data contains rows of varying lengths (ragged rows) and the first row has fewer columns than subsequent rows, _normalize_tabular_data previously computed headers_pad using only len(rows[0]). When headers was shorter than the maximum row length, the headers list remained shorter than the total number of columns, causing zip(cols, aligns, minwidths) to truncate the table columns. Now headers_pad uses the maximum column count across all non-separating data rows, ensuring all table columns are properly preserved and aligned. Fixes astanin#494
82d4bd1 to
8ee2ce1
Compare
|
Hi maintainers, when you have time, could you please review this fix for #494? It includes a regression test for ragged rows with shorter headers, and the full test suite passes locally. Thank you! |
|
One edge case in the new from tabulate import SEPARATING_LINE, tabulate
print(tabulate([SEPARATING_LINE], headers=["tail"], tablefmt="simple"))On base Using Grid-only separator tables already fail on the base, so I am not counting that separate behavior as a regression here. AI-assisted investigation and testing; no downstream incident claim. |
Problem
Fixes #494.
When tabular data contains rows of varying lengths (ragged rows) and the first row has fewer columns than subsequent rows,
_normalize_tabular_datacomputedheaders_padusing onlylen(rows[0]):If
headerswas shorter than the maximum column count across all data rows (e.g.tabulate([["a"], ["b", "KEEP"]], headers=["tail"])),headersremained shorter than the total number of columns. Later,zip(cols, aligns_copy, minwidths)truncated the columns to the length ofminwidths(derived fromheaders), silently dropping data columns like"KEEP".Solution
_normalize_tabular_datato computeheaders_padusing the maximum column count across all non-separating data rows (max(len(r) for r in rows if not _is_separating_line(r))).test_ragged_rows_with_short_headersintest/test_regression.pyto verify that columns beyond the first row's width are preserved when short headers are supplied.Verification
pytest test/): 307 passed, 60 skipped, 0 failed.