One function

_normalize_tabular_data in astanin/python-tabulate

The author described this change as fix #9: tabulate iterator of iterators with headers. It counts as a record because the check below fails on the code as it stood at 0ab146122 and passes on e20994384, with nothing else changed between the two runs.

Fix saved2013-08-09
Sharing licenceMIT · LICENSE
Change size+7 3

What the code was meant to do, written into the code itself as a docstring

Transform a supported data type to a list of lists, and a list of headers. Supported tabular data types: * list-of-lists or another iterable of iterables * 2D NumPy arrays * dict of iterables (usually used with headers="keys") * pandas.DataFrame (usually used with headers="keys") The first row can be used as headers if headers="firstrow", column indices can be used as headers if headers="keys".

The change

4343 # take headers from the first row if necessary
4444 if headers == "firstrow" and len(rows) > 0:
4545 headers = list(map(_text_type, rows[0])) # headers should be strings
46- rows = list(rows[1:])
46+ rows = rows[1:]
4747
48+ headers = list(headers)
49+ rows = list(map(list,rows))
50+
4851 # pad with empty headers for initial columns if necessary
4952 if headers and len(rows) > 0:
5053 nhs = len(headers)
5154 ncols = len(rows[0])
52- headers = [u""]*(ncols - nhs) + list(headers)
55+ if nhs < ncols:
56+ headers = [u""]*(ncols - nhs) + headers
5357
54- return list(map(list,rows)), list(headers)
58+ return rows, headers

The check that tells the two apart

failpass·test_input.py::test_iterable_of_iterables_headers

Check file test_input.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before it0ab146122d2d3da81675234f6021fa8c012d074d
Broken version dated2013-08-09
Moduletabulate
Units changed_normalize_tabular_data
Fingerprint1b9e406777f2676d
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.

Other bugs found in astanin/python-tabulate