Improve login in `parse_data`.

This commit is contained in:
ljnsn 2022-11-10 00:44:46 +01:00
parent e96fb14710
commit 37c52355f4
1 changed files with 32 additions and 28 deletions

View File

@ -12,7 +12,9 @@ def parse_data(backend, rows, headers=True, columns=None, skiprows=0):
next(rows)
for i, row in enumerate(rows):
# row is a list of cells
if headers and i == 0 and not columns:
if i == 0:
if not columns:
if headers:
repeat_until = -1
repeat_value = None
# columns as lists in a dictionary
@ -37,15 +39,17 @@ def parse_data(backend, rows, headers=True, columns=None, skiprows=0):
while f"{column_name}.{idx}" in columns:
idx += 1
columns.append(f"{column_name}.{idx}")
elif i == 0:
else:
# without headers, assign generic numbered column names
columns = columns if columns else [f"column.{j}" for j in range(len(row))]
if i == 0:
columns = [f"column.{j}" for j in range(len(row))]
df_dict = OrderedDict((column, []) for column in columns)
# create index for the column headers
col_index = {j: column for j, column in enumerate(columns)}
if headers:
continue
for j, cell in enumerate(row):
if j < len(col_index):
value, _ = backend.get_value(cell, parsed=True)