Commit 64e83217 authored by Pierre Dittgen's avatar Pierre Dittgen

Fix duplicate-header crash

parent 94be30f4
......@@ -192,6 +192,7 @@ def repair_core(dataset: tablib.Dataset, schema_field_names):
last_nonempty_header_col = None
first_nonempty_header_col = None
empty_header_cols = []
duplicate_header_map = {}
for i, head in enumerate(dataset.headers):
......@@ -214,11 +215,19 @@ def repair_core(dataset: tablib.Dataset, schema_field_names):
append_col(rejected_cols_dataset, dataset.get_col(i), head)
# Move duplicate columns in a special dataset
# Rename and move duplicate columns in a special dataset
if head in column_names_dict:
ver = duplicate_header_map.get(head) or 1
fixed_head = '{}~{}'.format(head, ver)
duplicate_header_map[head] = ver + 1
message_substitutions={'column-number': i+1, 'column-name': head}))
append_col(rejected_cols_dataset, dataset.get_col(i), head)
'column-name': head,
'fixed-column-name': fixed_head,
# not used by Validata but needed to avoid
# a KeyError in message substitution
'column_numbers': ''}))
append_col(rejected_cols_dataset, dataset.get_col(i), fixed_head)
# Normal case
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment