Add a left-most index column.
(rows, index)
| 1429 | |
| 1430 | |
| 1431 | def _prepend_row_index(rows, index): |
| 1432 | """Add a left-most index column.""" |
| 1433 | if index is None or index is False: |
| 1434 | return rows |
| 1435 | if isinstance(index, Sized) and len(index) != len(rows): |
| 1436 | raise ValueError( |
| 1437 | "index must be as long as the number of data rows: " |
| 1438 | + f"len(index)={len(index)} len(rows)={len(rows)}" |
| 1439 | ) |
| 1440 | sans_rows, separating_lines = _remove_separating_lines(rows) |
| 1441 | new_rows = [] |
| 1442 | index_iter = iter(index) |
| 1443 | for row in sans_rows: |
| 1444 | index_v = next(index_iter) |
| 1445 | new_rows.append([index_v] + list(row)) |
| 1446 | rows = new_rows |
| 1447 | _reinsert_separating_lines(rows, separating_lines) |
| 1448 | return rows |
| 1449 | |
| 1450 | |
| 1451 | def _bool(val): |
no test coverage detected