(cell_list: List["Cell"])
| 680 | |
| 681 | |
| 682 | def cell_list_to_rect(cell_list: List["Cell"]) -> List[List[Optional[str]]]: |
| 683 | if not cell_list: |
| 684 | return [] |
| 685 | |
| 686 | rows: Dict[int, Dict[int, Optional[str]]] = defaultdict(dict) |
| 687 | |
| 688 | row_offset = min(c.row for c in cell_list) |
| 689 | col_offset = min(c.col for c in cell_list) |
| 690 | |
| 691 | for cell in cell_list: |
| 692 | row = rows.setdefault(int(cell.row) - row_offset, {}) |
| 693 | row[cell.col - col_offset] = cell.value |
| 694 | |
| 695 | if not rows: |
| 696 | return [] |
| 697 | |
| 698 | all_row_keys = chain.from_iterable(row.keys() for row in rows.values()) |
| 699 | rect_cols = range(max(all_row_keys) + 1) |
| 700 | rect_rows = range(max(rows.keys()) + 1) |
| 701 | |
| 702 | # Return the values of the cells as a list of lists where each sublist |
| 703 | # contains all of the values for one row. The Google API requires a rectangle |
| 704 | # of updates, so if a cell isn't present in the input cell_list, then the |
| 705 | # value will be None and will not be updated. |
| 706 | return [[rows[i].get(j) for j in rect_cols] for i in rect_rows] |
| 707 | |
| 708 | |
| 709 | def quote(value: str, safe: str = "", encoding: str = "utf-8") -> str: |
no test coverage detected
searching dependent graphs…