Skip to content

Commit

Permalink
No public description
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 697793583
  • Loading branch information
colaboratory-team committed Nov 19, 2024
1 parent 948a9e6 commit 26bee3d
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions google/colab/sheets.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,16 @@ def as_df(self):
data = self.storage_strategy.read(self.worksheet)
return pd.DataFrame(data)

def update(self, df):
def update(self, df, **kwargs):
"""Update clears the sheet and replaces it with the provided dataframe.
Args:
df: the source data
**kwargs: additional arguments to pass to the gspread update method
"""
self._ensure_gspread_client()
self.worksheet.clear()
self.storage_strategy.write(self.worksheet, _to_frame(df))
self.storage_strategy.write(self.worksheet, _to_frame(df), **kwargs)

def display(self, height=600):
"""Display the embedded sheet in Colab.
Expand All @@ -211,7 +212,7 @@ def read(self, worksheet):
pass

@abc.abstractmethod
def write(self, worksheet, df):
def write(self, worksheet, df, **kwargs):
pass


Expand All @@ -222,9 +223,9 @@ def read(self, worksheet):
data = worksheet.get_values()
return pd.DataFrame(data)

def write(self, worksheet, df):
def write(self, worksheet, df, **kwargs):
data = [list(r) for _, r in df.iterrows()]
worksheet.update('', data)
worksheet.update('', data, **kwargs)


class HeaderStorageStrategy(InteractiveSheetStorageStrategy):
Expand All @@ -234,6 +235,6 @@ def read(self, worksheet):
data = worksheet.get_all_records()
return pd.DataFrame(data)

def write(self, worksheet, df):
def write(self, worksheet, df, **kwargs):
data = [list(df.columns)] + [list(r) for _, r in df.iterrows()]
worksheet.update('', data)
worksheet.update('', data, **kwargs)

0 comments on commit 26bee3d

Please sign in to comment.