Skip to content

Commit

Permalink
better arg passthrough
Browse files Browse the repository at this point in the history
  • Loading branch information
muddi900 committed Oct 26, 2024
1 parent 810505d commit e7f092b
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions gspread/worksheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,6 @@ def get_all_records(
return []

keys = entire_sheet[head - 1]
self.column_headers = keys
values = entire_sheet[head:]

if expected_headers is None:
Expand Down Expand Up @@ -615,6 +614,8 @@ def append_records(
rows: List[Dict[str, Any]],
ignore_extra_headers: bool = False,
default_blank: Any = "",
header_row: Optional[int] = None,
value_input_option: Optional[ValueInputOption] = None,
) -> None:
"""Appends records as rows to your data range.
Expand All @@ -627,10 +628,11 @@ def append_records(
:param default_blank: The value to use for missing columns in the data. Defaults to an empty string.
:type default_blank: Any
:raises GSpreadException: If extra headers are found in the data set and `ignore_extra_headers` is False.
"""

cols = self.column_headers
cols = self.get_column_headers(header_row)
insert_rows = []
for row in rows:
if not set(row).issubset(set(cols)) and not ignore_extra_headers:
Expand All @@ -641,16 +643,15 @@ def append_records(
insert_row.append(row.get(col, default_blank))
insert_rows.append(insert_row)

self.append_rows(
insert_rows,
value_input_option=ValueInputOption.user_entered,
)
self.append_rows(insert_rows, value_input_option=value_input_option)

def append_record(
self,
row: Dict[str, Any],
ignore_extra_headers: bool = False,
default_blank: Any = "",
header_row: Optional[int] = None,
value_input_option: Optional[ValueInputOption] = None,
) -> None:
"""Appends a dict as a row to your data range.
Expand All @@ -670,6 +671,8 @@ def append_record(
[row],
ignore_extra_headers=ignore_extra_headers,
default_blank=default_blank,
header_row=header_row,
value_input_option=value_input_option,
)

def insert_records(
Expand All @@ -678,6 +681,8 @@ def insert_records(
ignore_extra_headers: bool = False,
default_blank: Any = "",
insert_row: int = 2,
header_row: Optional[int] = None,
value_input_option: Optional[ValueInputOption] = None,
) -> None:
"""Insert records as rows to your data range at the stated row.
Expand Down Expand Up @@ -715,7 +720,8 @@ def insert_records(
self.insert_rows(
insert_rows,
row=insert_row,
value_input_option=ValueInputOption.user_entered,
value_input_option=value_input_option,
header_row=header_row,
)

def insert_record(
Expand All @@ -724,6 +730,8 @@ def insert_record(
ignore_extra_headers: bool = False,
default_blank: Any = "",
insert_row: int = 2,
header_row: Optional[int] = None,
value_input_option: Optional[ValueInputOption] = None,
) -> None:
"""Insert a dict as rows to your data range at the stated row.
Expand Down Expand Up @@ -752,6 +760,8 @@ def insert_record(
ignore_extra_headers=ignore_extra_headers,
insert_row=insert_row,
default_blank=default_blank,
header_row=header_row,
value_input_option=value_input_option,
)

def get_all_cells(self) -> List[Cell]:
Expand Down

0 comments on commit e7f092b

Please sign in to comment.