MCPcopy
hub / github.com/burnash/gspread / cell_list_to_rect

Function cell_list_to_rect

gspread/utils.py:682–706  ·  view source on GitHub ↗
(cell_list: List["Cell"])

Source from the content-addressed store, hash-verified

680
681
682def 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
709def quote(value: str, safe: str = "", encoding: str = "utf-8") -> str:

Callers 1

update_cellsMethod · 0.85

Calls 1

getMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…